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 @@ -128,15 +128,18 @@ def self.inherited(subclass)
128128 # If a proc is presented it is evaluated in the context of the entity so object
129129 # and the entity methods are available to it.
130130 #
131- # @example as: a proc
131+ # @example as: a proc or lambda
132132 #
133- # object = OpenStruct(awesomness: 'awesome_key', awesome: 'not-my-key' )
133+ # object = OpenStruct(awesomness: 'awesome_key', awesome: 'not-my-key', other: 'other-key' )
134134 #
135135 # class MyEntity < Grape::Entity
136- # expose :awesome, as: -> { object.awesomness }
136+ # expose :awesome, as: Proc.new { object.awesomeness }
137+ # expose :awesomeness, as: ->(object, opts) { object.other }
137138 # end
138139 #
139- # => { 'awesome_key': 'not-my-key' }
140+ # => { 'awesome_key': 'not-my-key', 'other-key': 'awesome_key' }
141+ #
142+ # Note the parameters passed in via the lambda syntax.
140143 #
141144 # @option options :if When passed a Hash, the attribute will only be exposed if the
142145 # runtime options match all the conditions passed in. When passed a lambda, the
Original file line number Diff line number Diff line change 3333 end
3434
3535 it 'returns the result if :as is a proc' do
36- fresh_class . expose :name , as : -> { object . name . reverse }
36+ fresh_class . expose :name , as : Proc . new { object . name . reverse }
37+ expect ( subject . key ( entity ) ) . to eq ( model . name . reverse )
38+ end
39+
40+ it 'returns the result if :as is a lambda' do
41+ fresh_class . expose :name , as : -> ( obj , opts ) { obj . name . reverse }
3742 expect ( subject . key ( entity ) ) . to eq ( model . name . reverse )
3843 end
3944 end
You can’t perform that action at this time.
0 commit comments