grape-entity icon indicating copy to clipboard operation
grape-entity copied to clipboard

Discussion on how to handle reopening exposures.

Open Nerian opened this issue 11 years ago • 2 comments

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

Nerian avatar Mar 12 '14 18:03 Nerian

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.

marshall-lee avatar Aug 24 '15 19:08 marshall-lee

@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.

marshall-lee avatar Aug 24 '15 19:08 marshall-lee