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
By default fast_jsonapi underscores the key names. It supports the same key transforms that are supported by AMS. Here is the syntax of specifying a key transform
151
+
152
+
```ruby
153
+
classMovieSerializer
154
+
includeFastJsonapi::ObjectSerializer
155
+
# Available options :camel, :camel_lower, :dash, :underscore(default)
156
+
set_key_transform :camel
157
+
end
158
+
```
159
+
Here are examples of how these options transform the keys
Attributes are defined in FastJsonapi using the `attributes` method. This method is also aliased as `attribute`, which is useful when defining a single attribute.
170
+
171
+
By default, attributes are read directly from the model property of the same name. In this example, `name` is expected to be a property of the object being serialized:
172
+
173
+
```ruby
174
+
classMovieSerializer
175
+
includeFastJsonapi::ObjectSerializer
176
+
177
+
attribute :name
178
+
end
179
+
```
180
+
181
+
Custom attributes that must be serialized but do not exist on the model can be declared using Ruby block syntax:
182
+
183
+
```ruby
184
+
classMovieSerializer
185
+
includeFastJsonapi::ObjectSerializer
186
+
187
+
attributes :name, :year
188
+
189
+
attribute :name_with_yeardo |object|
190
+
"#{object.name} (#{object.year})"
191
+
end
192
+
end
193
+
```
194
+
195
+
The block syntax can also be used to override the property on the object:
196
+
197
+
```ruby
198
+
classMovieSerializer
199
+
includeFastJsonapi::ObjectSerializer
200
+
201
+
attribute :namedo |object|
202
+
"#{object.name} Part 2"
203
+
end
204
+
end
205
+
```
206
+
137
207
### Compound Document
138
208
139
209
Support for top-level included member through ` options[:include] `.
@@ -169,69 +239,66 @@ end
169
239
Option | Purpose | Example
170
240
------------ | ------------- | -------------
171
241
set_type | Type name of Object | ```set_type :movie ```
242
+
set_id | ID of Object | ```set_id :owner_id ```
172
243
cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true, cache_length: 12.hours```
173
244
id_method_name | Set custom method name to get ID of an object | ```has_many :locations, id_method_name: :place_ids ```
174
245
object_method_name | Set custom method name to get related objects | ```has_many :locations, object_method_name: :places ```
175
246
record_type | Set custom Object Type for a relationship | ```belongs_to :owner, record_type: :user```
176
247
serializer | Set custom Serializer for a relationship | ```has_many :actors, serializer: :custom_actor```
177
248
249
+
### Instrumentation
178
250
179
-
## Contributing
251
+
`fast_jsonapi` also has builtin [Skylight](https://www.skylight.io/) integration. To enable, add the following to an initializer:
180
252
181
-
Please follow the steps on [contribution check](https://github.com/Netflix/fast_jsonapi/blob/master/CONTRIBUTING.md).
182
-
This gem is built using a gem building gem called [juwelier](https://github.com/flajann2/juwelier).
253
+
```ruby
254
+
require'fast_jsonapi/instrumentation/skylight'
255
+
```
183
256
184
-
Beyond just editing source code, you’ll be interacting with the gem using rake a lot. To see all the tasks available with a brief description, you can run:
257
+
Skylight relies on `ActiveSupport::Notifications` to track these two core methods. If you would like to use these notifications without using Skylight, simply require the instrumentation integration:
185
258
186
-
```bash
187
-
rake -T
259
+
```ruby
260
+
require'fast_jsonapi/instrumentation'
188
261
```
189
262
190
-
### Updating Project information
191
-
You can update the project information of the gem by updating the [Rakefile](Rakefile). Then you need to generate a new gemspec:
263
+
The two instrumented notifcations are supplied by these two constants:
0 commit comments