jsonapi_mapper 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/jsonapi_mapper/version.rb +1 -1
- data/lib/jsonapi_mapper.rb +9 -9
- 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: 47223d6620e9fc3fff6740ffc29ab2667b18e2b8
|
4
|
+
data.tar.gz: a8453219e94d3fb0f412f4c64256ce8e563fb399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54fe745ec69e3012480a44b5a05eb67b764727a3c19be1beb45632962dcb4cf2e1ed4329dbc13e130e6d582bdd1d69775ca029600c9ea06cc23f7e2043ce69ae
|
7
|
+
data.tar.gz: 3b11530b50b1159e272e7b4d6957acef70c539a3a37390bccfb5ea5f80b2ef6217adc6e39300b02da68fbed33ab4639112458e15867a56acbf5e0730a43ade72
|
data/README.md
CHANGED
@@ -71,13 +71,12 @@ See the specs directory for more examples.
|
|
71
71
|
)
|
72
72
|
|
73
73
|
# The document data lives in mapper.data
|
74
|
-
# It
|
74
|
+
# It could be a simple or multiple resource response.
|
75
75
|
# If you want to check wether the document had a single resource
|
76
76
|
# or a collection as its primary data you can use the following methods.
|
77
77
|
mapper.collection? # Was primary document data a collection?
|
78
78
|
mapper.single? # Was primary document data a single resource?
|
79
79
|
|
80
|
-
person = mapper.data.first
|
81
80
|
|
82
81
|
# The rest of the included resources live in mapper.included
|
83
82
|
others = mapper.included
|
data/lib/jsonapi_mapper.rb
CHANGED
@@ -18,7 +18,7 @@ module JsonapiMapper
|
|
18
18
|
|
19
19
|
class DocumentMapper
|
20
20
|
attr_accessor :document, :unscoped, :types, :renames, :resources,
|
21
|
-
:included, :
|
21
|
+
:included, :data
|
22
22
|
|
23
23
|
def initialize(document, unscoped, rules, renames)
|
24
24
|
self.document = document.deep_symbolize_keys
|
@@ -27,11 +27,11 @@ module JsonapiMapper
|
|
27
27
|
self.resources = {}
|
28
28
|
setup_types(rules)
|
29
29
|
|
30
|
-
main = if
|
31
|
-
if
|
32
|
-
|
30
|
+
main = if data = self.document[:data]
|
31
|
+
if data.is_a?(Array)
|
32
|
+
data.map{|r| build_resource(r) }.compact.collect(&:object)
|
33
33
|
else
|
34
|
-
|
34
|
+
build_resource(data).try(:object)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -41,7 +41,7 @@ module JsonapiMapper
|
|
41
41
|
|
42
42
|
resources.each{|_,r| assign_relationships(r) }
|
43
43
|
|
44
|
-
self.
|
44
|
+
self.data = main
|
45
45
|
self.included = rest.try(:map, &:object) || []
|
46
46
|
end
|
47
47
|
|
@@ -164,7 +164,7 @@ module JsonapiMapper
|
|
164
164
|
end
|
165
165
|
|
166
166
|
def collection?
|
167
|
-
|
167
|
+
data.is_a?(Array)
|
168
168
|
end
|
169
169
|
|
170
170
|
def single?
|
@@ -179,8 +179,8 @@ module JsonapiMapper
|
|
179
179
|
all.select{|o| o.is_a?(cls)}.map(&blk)
|
180
180
|
end
|
181
181
|
|
182
|
-
def
|
183
|
-
collection? ?
|
182
|
+
def data_mappable
|
183
|
+
collection? ? data : [data].compact
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nubis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|