Skip to content

Commit 4c991ea

Browse files
author
James McCarthy
committed
Add documentation to the as: option.
1 parent 9b63f85 commit 4c991ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/grape_entity/entity.rb

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

0 commit comments

Comments
 (0)