grape-entity
grape-entity copied to clipboard
Discussion on how to handle reopening exposures.
Example.
class Person < Grape::Entity
expose :user do
expose(:in_first) { |_| 'value' }
end
end
class Student < Person
expose :user do
expose(:user_id) { |_| 'value' }
expose(:user_display_id, as: :display_id) { |_| 'value' }
end
end
- Current behaviour is that both exposures are merged.
- @dblock expressed his concern that this does not follow the same logic as redefining a method: The old method gets overwritten; so if you want to call it, you would use
super.
related: https://github.com/intridea/grape-entity/pull/63
I like the idea the of 'reopening' nested exposures. It's conventient for something like meta: { ... } containers to which subclasses could add some new fields.
It is also good from the implementation point of view. The entity class itself is a nested exposure (container of exposures) and obviously it should be extendable when making subclasses.
@dblock expressed his concern that this does not follow the same logic as redefining a method
The new conception of exposures is that they don't simulate method definitions — they simultate method calls.