Comments (9)
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.
+1 render_as_hash
from blueprinter.
I'm curious to know in what use case you are running into that returning a hash would be needed?
from blueprinter.
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.
@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.
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.
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.
- render_as_hash is a little ugly, but it certainly does what it says.
- publish / prepublish seems to abstract.
- as_json is the existing method in AMS: http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json. Personally I don't love it since JSON has the connotation of being a string so that can cause some confusion.
from blueprinter.
It's been too long since I've seen a Churchill quote on a PR 😂
from blueprinter.
#73 merged and released in 0.4.0
from blueprinter.
Related Issues (20)
- Transformer mutates original hash
- Discussion of a stable reflection API HOT 3
- Something weird when using transform. Use case: to lower camelCase HOT 2
- lazy load for association HOT 3
- Render one blueprint inside another? HOT 2
- Is there a way to exclude fields and associations and pass/process a block HOT 2
- Oj does not work after version 3.13 HOT 8
- "LocalJumpError: unexpected return" after update to 1.0 HOT 7
- How to create a field that is derived from other fields that are defined in the blueprint? HOT 1
- [bug] config.sort_fields_by = :definition causes SystemStackError: stack level too deep HOT 3
- [Feature Request][Rails] Render views from ActionController::API controllers HOT 5
- [Question/Support] Set one view as the default view HOT 3
- Mixed suggestions HOT 6
- Move global configuration HOT 6
- Extractor configurability HOT 5
- Separate internal options from external ones HOT 2
- Deprecate DateTimeFormatter HOT 3
- Implement association as it's own thing HOT 7
- [Feature Request] Support for nested associations defined at callsite HOT 1
- [bug] V 1.0.2 - Issue with Association when including custom name HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blueprinter.