You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are sometimes that you want to pass additional option or parameter to nested exposure. Assume that you need to expose an address for a contact info, but it has both two different format: **full** and **simple**. You can pass an additional `full_format` option to specify that if the nested entity should render address in `:full` format.
314
+
Sometimes you want to pass additional options or parameters to nested a exposure. For example, let's say that you need to expose an address for a contact info and it has two different formats: **full** and **simple**. You can pass an additional `full_format` option to specify which format to render.
315
315
316
316
```ruby
317
317
# api/contact.rb
@@ -332,21 +332,21 @@ expose :stree do |instance, options|
**Notice**: In the above code, you should pay attention to [**Safe Exposure**](#safe-exposure) yourself, for example, `instance.address` might be `nil`, in this situation, it is better to expose it as nil directly.
335
+
**Notice**: In the above code, you should pay attention to [**Safe Exposure**](#safe-exposure) yourself. For example, `instance.address` might be `nil` and it is better to expose it as nil directly.
336
336
337
337
#### Attribute Path Tracking
338
338
339
-
Sometimes, especially when there are nested attributes, you might want to know which attribute it
340
-
is being exposed. For example, some APIs allow user provide a parameter to control which fields
339
+
Sometimes, especially when there are nested attributes, you might want to know which attribute
340
+
is being exposed. For example, some APIs allow users to provide a parameter to control which fields
341
341
will be included in (or excluded from) the response.
342
342
343
-
Grape entity can track the path of each attribute, then you could access it during condition check
344
-
or runtime exposure, via `options[:attr_path]`.
343
+
GrapeEntity can track the path of each attribute, which you can access during conditions checking
344
+
or runtime exposure via `options[:attr_path]`.
345
345
346
-
Attribute path is an array. The last item of this array is the name (alias) of current attribute.
347
-
And if the attribute is nested, the former items are names (aliases) of its ancestor attributes.
346
+
The attribute path is an array. The last item of this array is the name (alias) of current attribute.
347
+
If the attribute is nested, the former items are names (aliases) of its ancestor attributes.
348
348
349
-
Here is an example shows what the attribute path will be.
0 commit comments