support dynamic attributes & merging collection values#172
support dynamic attributes & merging collection values#172danhodge wants to merge 1 commit intoruby-grape:masterfrom
Conversation
Work in progress. Allows the parent attribute of a nested attribute structure to be a dynamic attribute that is evaluated during rendering. Adds a 'combine' option that can be used when exposing a collection of items in a single presenter that controls how the individual items are combined. No value maintains the existing behavior, where each item is rendered as JSON and appended to the Array, while a value of :merge results in each item's JSON representation being Hash#merge'd into a single Hash.
|
I am personally not a huge fan of naming conventions. There should be an explicit way to tackle this. Try to propose a cleaner DSL? Maybe something as simple as an expose do
{ x: 1, y: 2 }
end |
|
Hello! This feature seems good, but:
Please don't! It'll be better to implement it in terms of expose :by_date, as: -> (obj, opts) { obj.date } do
expose :first_name
expose :last_name
endAlso the question is how it will work with |
|
And:
What is this? I don't see any merging in your code. |
|
I only used the naming convention for prototyping purposes, I like the |
|
@marshall-lee Does the Can you comment on what you think about the key-less extension ( |
This is the start of my proposed solution to the problem I outlined on the mailing list here. It doesn't add general purpose dynamic attribute, it just allows you to evaluate the 'parent' attribute of a nested attribute structure dynamically through a hacky naming convention (
__prefix on the attribute name). I would have rather used a block to evaluate the value of the dynamic attribute, but I wasn't sure what all of the the implications of creating aNestingExposurewere.