motion-json-api 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/motion-json-api/exceptions.rb +0 -3
- data/lib/motion-json-api/resource.rb +5 -12
- data/lib/motion-json-api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd899f2086a06cc4c985b5b91e6284cf990b230
|
4
|
+
data.tar.gz: 723dd9777eda173951bf011f28e8cfd310d3f7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c129d55efaf7257cfa16827d022c86d333deee318913f099256ab194f440591d6d6b5f2f7c3fcbd38d116792f7231e82144e22fdd08493199c738ace6e4386c
|
7
|
+
data.tar.gz: 93f30105c966a485ab672f8199eaae4427cc5cb2f40ad234d55f12fa614278b08fd35a3769efafc99a927ccdf1a766f910a0e4fd74e7f07bbdf7657ac72410ab
|
@@ -38,20 +38,16 @@ module MotionJsonApi
|
|
38
38
|
def self.attribute(attribute, options = {})
|
39
39
|
key = options.fetch(:key, attribute)
|
40
40
|
define_method(key) do
|
41
|
-
self.attributes.fetch(attribute.to_s)
|
42
|
-
raise UndefinedAttribute, "Couldn't find attribute:`#{attribute}` in #{self.attributes}"
|
43
|
-
end
|
41
|
+
self.attributes.fetch(attribute.to_s, nil)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
def self.has_one(relation, options = {})
|
48
46
|
key = options.fetch(:key, relation)
|
49
47
|
define_method(key) do
|
50
|
-
relationship = self.relationships.fetch(relation.to_s)
|
51
|
-
raise UndefinedHasOneRelation, "Couldn't find relation:`#{relation}` in #{self.relationships}"
|
52
|
-
end
|
48
|
+
relationship = self.relationships.fetch(relation.to_s, {})
|
53
49
|
|
54
|
-
data = relationship.fetch("data")
|
50
|
+
data = relationship.fetch("data", nil)
|
55
51
|
if data
|
56
52
|
object = _find_in_included(data["id"], data["type"])
|
57
53
|
payload = {"data" => object, "links" => relationship.fetch("links", {})}
|
@@ -65,11 +61,8 @@ module MotionJsonApi
|
|
65
61
|
def self.has_many(relation, options = {})
|
66
62
|
key = options.fetch(:key, relation)
|
67
63
|
define_method(key) do
|
68
|
-
relationship = self.relationships.fetch(relation.to_s)
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
relationship.fetch("data").map do |data|
|
64
|
+
relationship = self.relationships.fetch(relation.to_s, {})
|
65
|
+
relationship.fetch("data", []).map do |data|
|
73
66
|
object = _find_in_included(data["id"], data["type"])
|
74
67
|
Resource._object_handler({"data" => object}, self.top_level, self.included)
|
75
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-json-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joffrey Jaffeux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|