Skip to content

Commit 1cce99f

Browse files
author
James McCarthy
committed
Add documentation to the as: option.
1 parent af35d4a commit 1cce99f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/grape_entity/entity.rb

+13
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ def self.inherited(subclass)
125125
# should be exposed by the entity.
126126
#
127127
# @option options :as Declare an alias for the representation of this attribute.
128+
# If a proc is presented it is evaluated in the context of the entity so object
129+
# and the entity methods are available to it.
130+
#
131+
# @example as: a proc
132+
#
133+
# object = OpenStruct(awesomness: 'awesome_key', awesome: 'not-my-key' )
134+
#
135+
# class MyEntity < Grape::Entity
136+
# expose :awesome, as: -> { object.awesomness }
137+
# end
138+
#
139+
# => { 'awesome_key': 'not-my-key' }
140+
#
128141
# @option options :if When passed a Hash, the attribute will only be exposed if the
129142
# runtime options match all the conditions passed in. When passed a lambda, the
130143
# lambda will execute with two arguments: the object being represented and the

0 commit comments

Comments
 (0)