jsonapi-resources 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/jsonapi/association.rb +3 -3
- data/lib/jsonapi/resource.rb +1 -1
- data/lib/jsonapi/resources/version.rb +1 -1
- data/test/fixtures/active_record.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eb2793fc0bf0e02a6224a77143049fb497b7fcb
|
4
|
+
data.tar.gz: 9e4af0e18b535c6bb61252f3e6b7f4d6c45d55d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e93a730c3e5fbc508463c16a4cf54553697d2307b99bc320850b1486a6d312795ed56b1c4aba89075b3523317ffe64b85167cc8c0e748c9819f6923e97711a2e
|
7
|
+
data.tar.gz: 98b86070d30b544ecf95398956a92c84200d25867323467d3f0bd1cd591b2456a7b9015b592d84899f5936f885858f252d8756643f76ecf8e32352ba702637ec
|
data/README.md
CHANGED
@@ -188,7 +188,7 @@ The association methods support the following options:
|
|
188
188
|
* `class_name` - a string specifying the underlying class for the related resource
|
189
189
|
* `primary_key` - the primary key to the related resource, if different than `id`
|
190
190
|
* `key` - the key in the resource that identifies the related resource, if different than `<resource_name>_id`
|
191
|
-
* `
|
191
|
+
* `acts_as_set` - allows the entire set of related records to be replaced in one operation. Defaults to false if not set.
|
192
192
|
|
193
193
|
Examples:
|
194
194
|
|
@@ -197,7 +197,7 @@ Examples:
|
|
197
197
|
attributes :id, :body
|
198
198
|
has_one :post
|
199
199
|
has_one :author, class_name: 'Person'
|
200
|
-
has_many :tags,
|
200
|
+
has_many :tags, acts_as_set: true
|
201
201
|
end
|
202
202
|
```
|
203
203
|
|
@@ -377,8 +377,7 @@ JR has a couple of helper methods available to assist you with setting up routes
|
|
377
377
|
|
378
378
|
##### `jsonapi_resources`
|
379
379
|
|
380
|
-
Like `resources` in ActionDispatch provides
|
381
|
-
controller actions. This will also setup mappings for relationship URLs for a resource's associations. For example
|
380
|
+
Like `resources` in ActionDispatch, `jsonapi_resources` provides resourceful routes mapping between HTTP verbs and URLs and controller actions. This will also setup mappings for relationship URLs for a resource's associations. For example
|
382
381
|
|
383
382
|
```
|
384
383
|
require 'jsonapi/routing_ext'
|
data/lib/jsonapi/association.rb
CHANGED
@@ -5,7 +5,7 @@ module JSONAPI
|
|
5
5
|
@options = options
|
6
6
|
@key = options[:key] ? options[:key].to_sym : nil
|
7
7
|
@primary_key = options.fetch(:primary_key, 'id').to_sym
|
8
|
-
@
|
8
|
+
@acts_as_set = options.fetch(:acts_as_set, false) == true
|
9
9
|
end
|
10
10
|
|
11
11
|
def key
|
@@ -16,8 +16,8 @@ module JSONAPI
|
|
16
16
|
@primary_key
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@
|
19
|
+
def acts_as_set
|
20
|
+
@acts_as_set
|
21
21
|
end
|
22
22
|
|
23
23
|
def serialize_type_name
|
data/lib/jsonapi/resource.rb
CHANGED
@@ -295,7 +295,7 @@ module JSONAPI
|
|
295
295
|
associations = []
|
296
296
|
|
297
297
|
@_associations.each do |key, association|
|
298
|
-
if association.is_a?(JSONAPI::Association::HasOne) || association.
|
298
|
+
if association.is_a?(JSONAPI::Association::HasOne) || association.acts_as_set
|
299
299
|
associations.push(key)
|
300
300
|
end
|
301
301
|
end
|
@@ -331,8 +331,8 @@ class PostResource < JSONAPI::Resource
|
|
331
331
|
|
332
332
|
has_one :author, class_name: 'Person'
|
333
333
|
has_one :section
|
334
|
-
has_many :tags,
|
335
|
-
has_many :comments,
|
334
|
+
has_many :tags, acts_as_set: true
|
335
|
+
has_many :comments, acts_as_set: false
|
336
336
|
def subject
|
337
337
|
@object.title
|
338
338
|
end
|