Giter Club home page Giter Club logo

Comments (9)

dlcarter avatar dlcarter commented on June 3, 2024 2

To mangle a Churchill quote, I think render_as_hash is the worst option, except for all the others. So I'd +1 that as well

from blueprinter.

allanrsmith avatar allanrsmith commented on June 3, 2024 1

+1 render_as_hash

from blueprinter.

philipqnguyen avatar philipqnguyen commented on June 3, 2024

I'm curious to know in what use case you are running into that returning a hash would be needed?

from blueprinter.

ojab avatar ojab commented on June 3, 2024

I'm using server-side data normalization (and not using blueprinter [yet]) and all models are returned in a { [model_name]: [serialized_array] } hash, so something like

render json: { first_models: FirstModelBlueprint.render_as_hash(first_models),
               second_models: SecondModelBlueprint.render_as_hash(second_models) }

will be useful.
What is the proper way to do it right now?

from blueprinter.

philipqnguyen avatar philipqnguyen commented on June 3, 2024

@ojab Totally makes sense. Right now there is no proper way of doing it with Blueprinter. I think what @amayer171 suggested about creating a new render_as_hash that utilizes the prepare method makes sense. Would any of you want to take a stab at a PR for it?

from blueprinter.

ojab avatar ojab commented on June 3, 2024

I'd like yo take a stab, but render_as_hash name looks quite ugly (and long) to me tbh.
Since #67 is not closed yet — maybe it should be publish/prepublish? Or just plain and understandable to_json/as_json?

from blueprinter.

amayer171 avatar amayer171 commented on June 3, 2024

My use case is that I'd like to start using blueprinter for nested objects in my existing serializers. These existing serializers expect a hash rather than a string because they provide their own stringify implementation so that they can stringify in the last step. Otherwise the blueprinter result will be a string literal with hash syntax escaped.

from blueprinter.

amayer171 avatar amayer171 commented on June 3, 2024

It's been too long since I've seen a Churchill quote on a PR 😂

from blueprinter.

philipqnguyen avatar philipqnguyen commented on June 3, 2024

#73 merged and released in 0.4.0

from blueprinter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.