File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -130,15 +130,18 @@ def self.inherited(subclass)
130130 # If a proc is presented it is evaluated in the context of the entity so object
131131 # and the entity methods are available to it.
132132 #
133- # @example as: a proc
133+ # @example as: a proc or lambda
134134 #
135- # object = OpenStruct(awesomness: 'awesome_key', awesome: 'not-my-key' )
135+ # object = OpenStruct(awesomness: 'awesome_key', awesome: 'not-my-key', other: 'other-key' )
136136 #
137137 # class MyEntity < Grape::Entity
138- # expose :awesome, as: -> { object.awesomness }
138+ # expose :awesome, as: proc { object.awesomeness }
139+ # expose :awesomeness, as: ->(object, opts) { object.other }
139140 # end
140141 #
141- # => { 'awesome_key': 'not-my-key' }
142+ # => { 'awesome_key': 'not-my-key', 'other-key': 'awesome_key' }
143+ #
144+ # Note the parameters passed in via the lambda syntax.
142145 #
143146 # @option options :if When passed a Hash, the attribute will only be exposed if the
144147 # runtime options match all the conditions passed in. When passed a lambda, the
Original file line number Diff line number Diff line change 3535 end
3636
3737 it 'returns the result if :as is a proc' do
38- fresh_class . expose :name , as : -> { object . name . reverse }
38+ fresh_class . expose :name , as : proc { object . name . reverse }
39+ expect ( subject . key ( entity ) ) . to eq ( model . name . reverse )
40+ end
41+
42+ it 'returns the result if :as is a lambda' do
43+ fresh_class . expose :name , as : -> ( obj , _opts ) { obj . name . reverse }
3944 expect ( subject . key ( entity ) ) . to eq ( model . name . reverse )
4045 end
4146 end
You can’t perform that action at this time.
0 commit comments