Open
Description
Suppose this case:
class GeneralInfo < Grape::Entity
expose :gender, :age
end
class Student < Grape::Entity
expose :info, using: GeneralInfo
expose :info do
expose :grade
end
end
Student.represent({info: { gender: 'male', age: 25 }, grade: 5 }, serializable: true)
# => {:info=>{:grade=>5}}
But I assume info[:gender]
and info[:age]
to be exposed too. Also:
class Person < Grape::Entity
expose :info do
expose(:gender) { |obj| object[:info][:gender] }
expose(:age) { |obj| object[:info][:age] }
end
end
class Student < Person
expose :info do
expose :grade
end
end
Student.represent({info: { gender: 'male', age: 25 }, grade: 5 }, serializable: true)
# => {:info=>{:gender=>"male", :age=>25, :grade=>5}}
Since we decided not to rewrite previously defined exposures in #151 then more consistent behavior would be make these cases act identical. It's good to think of presenter exposures (with :using
option) as a nested exposures incapsulated in the separate classes.
Ones who want an old rewriting behavior should use conditional exposures (:if
, :unless
options).