@@ -23,13 +23,13 @@ module API
23
23
expose :user_type , :user_id , if: lambda { |status , options | status.user.public? }
24
24
expose :contact_info do
25
25
expose :phone
26
- expose :address , using: API ::Address
26
+ expose :address , using: API ::Entities :: Address
27
27
end
28
28
expose :digest do |status , options |
29
29
Digest ::MD5 .hexdigest status.txt
30
30
end
31
- expose :replies , using: API ::Status , as: :responses
32
- expose :last_reply , using: API ::Status do |status , options |
31
+ expose :replies , using: API ::Entities :: Status , as: :responses
32
+ expose :last_reply , using: API ::Entities :: Status do |status , options |
33
33
status.replies.last
34
34
end
35
35
@@ -78,13 +78,13 @@ The field lookup takes several steps
78
78
Don't derive your model classes from ` Grape::Entity ` , expose them using a presenter.
79
79
80
80
``` ruby
81
- expose :replies , using: API ::Status , as: :responses
81
+ expose :replies , using: API ::Entities :: Status , as: :responses
82
82
```
83
83
84
84
Presenter classes can also be specified in string format, which helps with circular dependencies.
85
85
86
86
``` ruby
87
- expose :replies , using: " API::Status" , as: :responses
87
+ expose :replies , using: " API::Entities:: Status" , as: :responses
88
88
```
89
89
90
90
#### Conditional Exposure
@@ -116,15 +116,15 @@ Supply a block to define a hash using nested exposures.
116
116
``` ruby
117
117
expose :contact_info do
118
118
expose :phone
119
- expose :address , using: API ::Address
119
+ expose :address , using: API ::Entities :: Address
120
120
end
121
121
```
122
122
123
123
You can also conditionally expose attributes in nested exposures:
124
124
``` ruby
125
125
expose :contact_info do
126
126
expose :phone
127
- expose :address , using: API ::Address
127
+ expose :address , using: API ::Entities :: Address
128
128
expose :email , if: lambda { |instance , options | options[:type ] == :full }
129
129
end
130
130
```
@@ -268,7 +268,7 @@ data.as_json
268
268
Expose under a different name with ` :as ` .
269
269
270
270
``` ruby
271
- expose :replies , using: API ::Status , as: :responses
271
+ expose :replies , using: API ::Entities :: Status , as: :responses
272
272
```
273
273
274
274
#### Format Before Exposing
@@ -319,7 +319,7 @@ expose :contact_info do
319
319
expose :phone
320
320
expose :address do |instance , options |
321
321
# use `#merge` to extend options and then pass the new version of options to the nested entity
322
- API ::Address .represent instance.address, options.merge(full_format: instance.need_full_format?)
322
+ API ::Entities :: Address .represent instance.address, options.merge(full_format: instance.need_full_format?)
323
323
end
324
324
expose :email , if: lambda { |instance , options | options[:type ] == :full }
325
325
end
0 commit comments