json_api_client 1.0.0.beta6 → 1.0.0.beta7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/json_api_client/associations/base_association.rb +8 -0
- data/lib/json_api_client/associations/belongs_to.rb +0 -4
- data/lib/json_api_client/associations/has_many.rb +0 -3
- data/lib/json_api_client/associations/has_one.rb +2 -3
- data/lib/json_api_client/helpers/dirty.rb +1 -1
- data/lib/json_api_client/included_data.rb +9 -12
- data/lib/json_api_client/relationships/relations.rb +6 -0
- data/lib/json_api_client/resource.rb +32 -2
- data/lib/json_api_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5100ace657cbe5030d9b34777b0afd41a8f5a734
|
4
|
+
data.tar.gz: 04ee78102f48525c3655be0cbcf5a1fd325b93c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 286d424f711a4ba8a8aaa104b3ee331dd9519bdba4e2f2ff99099454ab4a83970d0d435ceac34665d32a71390b419f1499191e910863ac4a128cade13cd25e46
|
7
|
+
data.tar.gz: 38fae6bbffb734965cf1e0153d6426fb8998e2dc076000d7f798f00c8f5d1786d3d19def4352645b2bbb7dced029934a4f98a52a5ca6e5cd4df8bae8860abc12
|
data/README.md
CHANGED
@@ -5,14 +5,13 @@ module JsonApiClient
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def has_one(attr_name, options = {})
|
8
|
-
# self.associations = self.associations + [HasOne::Association.new(attr_name, self, options)]
|
9
8
|
self.associations += [HasOne::Association.new(attr_name, self, options)]
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
class Association < BaseAssociation
|
14
|
-
def
|
15
|
-
|
13
|
+
def from_result_set(result_set)
|
14
|
+
result_set.first
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
@@ -19,24 +19,21 @@ module JsonApiClient
|
|
19
19
|
|
20
20
|
def data_for(method_name, definition)
|
21
21
|
# If data is defined, pull the record from the included data
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
# has_one link
|
30
|
-
record_for(data)
|
22
|
+
return nil unless data = definition["data"]
|
23
|
+
|
24
|
+
if data.is_a?(Array)
|
25
|
+
# has_many link
|
26
|
+
data.map do |link_def|
|
27
|
+
record_for(link_def)
|
31
28
|
end
|
32
29
|
else
|
33
|
-
#
|
34
|
-
|
30
|
+
# has_one link
|
31
|
+
record_for(data)
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
def has_link?(name)
|
39
|
-
data.has_key?(name)
|
36
|
+
data.has_key?(name.to_s)
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
@@ -319,6 +319,15 @@ module JsonApiClient
|
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
322
|
+
def as_json(*)
|
323
|
+
attributes.slice(:id, :type).tap do |h|
|
324
|
+
relationships.as_json.tap do |r|
|
325
|
+
h[:relationships] = r unless r.empty?
|
326
|
+
end
|
327
|
+
h[:attributes] = attributes.except(:id, :type).as_json
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
322
331
|
# Mark all attributes for this record as dirty
|
323
332
|
def set_all_dirty!
|
324
333
|
set_all_attributes_dirty
|
@@ -354,6 +363,7 @@ module JsonApiClient
|
|
354
363
|
mark_as_persisted!
|
355
364
|
if updated = last_result_set.first
|
356
365
|
self.attributes = updated.attributes
|
366
|
+
clear_changes_information
|
357
367
|
end
|
358
368
|
true
|
359
369
|
end
|
@@ -379,12 +389,28 @@ module JsonApiClient
|
|
379
389
|
protected
|
380
390
|
|
381
391
|
def method_missing(method, *args)
|
382
|
-
|
383
|
-
|
392
|
+
association = association_for(method)
|
393
|
+
|
394
|
+
return super unless association || (relationships && relationships.has_attribute?(method))
|
395
|
+
|
396
|
+
return nil unless relationship_definitions = relationships[method]
|
397
|
+
|
398
|
+
# look in included data
|
399
|
+
data = last_result_set.included.data_for(method, relationship_definitions)
|
400
|
+
return data if data
|
401
|
+
|
402
|
+
if association = association_for(method)
|
403
|
+
# look for a defined relationship url
|
404
|
+
if relationship_definitions["links"] && url = relationship_definitions["links"]["related"]
|
405
|
+
return association.data(url)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
nil
|
384
409
|
end
|
385
410
|
|
386
411
|
def respond_to_missing?(symbol, include_all = false)
|
387
412
|
return true if relationships && relationships.has_attribute?(symbol)
|
413
|
+
return true if association_for(symbol)
|
388
414
|
super
|
389
415
|
end
|
390
416
|
|
@@ -402,6 +428,10 @@ module JsonApiClient
|
|
402
428
|
self.class.schema.find(name)
|
403
429
|
end
|
404
430
|
|
431
|
+
def association_for(name)
|
432
|
+
self.class.associations.detect{|association| association.attr_name == name}
|
433
|
+
end
|
434
|
+
|
405
435
|
def attributes_for_serialization
|
406
436
|
attributes.except(*self.class.read_only_attributes).slice(*changed)
|
407
437
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: 1.3.1
|
176
176
|
requirements: []
|
177
177
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.4.
|
178
|
+
rubygems_version: 2.4.8
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: Build client libraries compliant with specification defined by jsonapi.org
|