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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1873feb8c0a1010e7761c7b688c772bed96f0b36
4
- data.tar.gz: d887f7bcea7afacaab8b813ae0fe2ebe384d9a3f
3
+ metadata.gz: 7cd899f2086a06cc4c985b5b91e6284cf990b230
4
+ data.tar.gz: 723dd9777eda173951bf011f28e8cfd310d3f7d9
5
5
  SHA512:
6
- metadata.gz: a49636a82da8d282d1dc5f26c9c0a3878a3c83cdc9001bdc88fd4147f9c57e9abbc59a709075e444ec69b30dcf351eaf5ee2e43f89d2e1b5051ececa7891b79e
7
- data.tar.gz: 7907a3ff8903fd5515f2879c2a9f3865099b9e1187bb58aa21a8245d4a241d67cf201f97a502c15b948bfe4542fa830d1d804d177e8de4db69d55537fc7d0f59
6
+ metadata.gz: 4c129d55efaf7257cfa16827d022c86d333deee318913f099256ab194f440591d6d6b5f2f7c3fcbd38d116792f7231e82144e22fdd08493199c738ace6e4386c
7
+ data.tar.gz: 93f30105c966a485ab672f8199eaae4427cc5cb2f40ad234d55f12fa614278b08fd35a3769efafc99a927ccdf1a766f910a0e4fd74e7f07bbdf7657ac72410ab
@@ -1,6 +1,3 @@
1
1
  module MotionJsonApi
2
2
  class UndefinedResource < StandardError; end
3
- class UndefinedAttribute < StandardError; end
4
- class UndefinedHasOneRelation < StandardError; end
5
- class UndefinedHasManyRelation < StandardError; end
6
3
  end
@@ -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) do
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) do
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) do
69
- raise UndefinedHasManyRelation, "Couldn't find relation:`#{relation}` in #{self.relationships}"
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
@@ -1,3 +1,3 @@
1
1
  module MotionJsonApi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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
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-23 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler