Replies: 1 comment 6 replies
-
Thank you for the suggestion. Basically I'd like the "model" layer to expose nested data structure (in this example, |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working with alba to see if I can easily do what I need with it.
I had an idea, what if alba could have simple API for doing "manual" nesting?
Imagine Employee with
name
,address_street
,address_country
.To result in:
nested
would just create a nested hash with that name -- inside the block, you are still in the same context as ever, and can callattributes
andattribute
that just work as usual on the "top" object.(I am not sure
nested
is exactly the right name for this method).This would get at the use case in #211. There you suggested using Rails
composed_of
, but I don't want to add functionality to my model that is really related to the "shape" I want to serialize in a specific context.There you also found another way using addiitonal "resource" classes. This is possible, but can get inconvenient when you have a lot of nesting.
For instance, this feature maybe also could be used for implementing Json:Api actually -- in a flexible way that lets someone build Json:Api or something similar that isn't exactly Json:Api , fairly simply:
I don't think this will get all the way to json:api -- For instance, not sure how to use it to handle json:api collections, and relationships are still too fiddly. But maybe it is helpful in defining json:api in simpler terms?
And it lets you do a variety of flexible things that are just similar to json:api in some ways. A simple additional alba API that makes easier a whole category of things you might want to do to "shape" your output.
This is just an idea right now for discussion, I'm not completely positive if it's a great idea.
Beta Was this translation helpful? Give feedback.
All reactions