jsonapi_mapper 0.1.1 → 0.1.2
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/lib/jsonapi_mapper/version.rb +1 -1
- data/lib/jsonapi_mapper.rb +14 -11
- 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: 46a0f72ab5eea90edcef9d6851bb26627dcb5af1
|
4
|
+
data.tar.gz: 74101764b455c9fb85a96894288b15f4046f9120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23be03d8e041f8b2f034e0f33dfff5c76f053bc99e78e1a88c4ed23d34826db9a38262869653d21a984521d8fa923b824f016f19e031959714b97d8f76b58940
|
7
|
+
data.tar.gz: 66493bd24c24da648b0d21c701a3fd5c18653c2769af2d6621bf91c579e06b643e2cf128a4a491a64ace29950a3449b978c05c82d6ae8a2c3d47e49a4b2d4ad9
|
data/lib/jsonapi_mapper.rb
CHANGED
@@ -18,21 +18,20 @@ module JsonapiMapper
|
|
18
18
|
|
19
19
|
class DocumentMapper
|
20
20
|
attr_accessor :document, :unscoped, :types, :renames, :resources,
|
21
|
-
:
|
21
|
+
:included, :data_mappable
|
22
22
|
|
23
23
|
def initialize(document, unscoped, rules, renames)
|
24
24
|
self.document = document.deep_symbolize_keys
|
25
25
|
self.renames = renames.deep_symbolize_keys
|
26
26
|
self.unscoped = unscoped.map(&:to_sym)
|
27
27
|
self.resources = {}
|
28
|
-
|
29
28
|
setup_types(rules)
|
30
|
-
|
31
|
-
main = if
|
32
|
-
if
|
33
|
-
|
29
|
+
|
30
|
+
main = if data_mappable = self.document[:data]
|
31
|
+
if data_mappable.is_a?(Array)
|
32
|
+
data_mappable.map{|r| build_resource(r) }.compact
|
34
33
|
else
|
35
|
-
[ build_resource(
|
34
|
+
[ build_resource(data_mappable) ].compact
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -42,7 +41,7 @@ module JsonapiMapper
|
|
42
41
|
|
43
42
|
resources.each{|_,r| assign_relationships(r) }
|
44
43
|
|
45
|
-
self.
|
44
|
+
self.data_mappable = main.try(:map, &:object) || []
|
46
45
|
self.included = rest.try(:map, &:object) || []
|
47
46
|
end
|
48
47
|
|
@@ -155,7 +154,7 @@ module JsonapiMapper
|
|
155
154
|
end
|
156
155
|
|
157
156
|
def all
|
158
|
-
(
|
157
|
+
(data_mappable + included)
|
159
158
|
end
|
160
159
|
|
161
160
|
def save_all
|
@@ -165,7 +164,7 @@ module JsonapiMapper
|
|
165
164
|
end
|
166
165
|
|
167
166
|
def collection?
|
168
|
-
|
167
|
+
data_mappable.size > 1
|
169
168
|
end
|
170
169
|
|
171
170
|
def single?
|
@@ -173,11 +172,15 @@ module JsonapiMapper
|
|
173
172
|
end
|
174
173
|
|
175
174
|
def map_data(cls, &blk)
|
176
|
-
|
175
|
+
data_mappable.select{|o| o.is_a?(cls)}.map(&blk)
|
177
176
|
end
|
178
177
|
|
179
178
|
def map_all(cls, &blk)
|
180
179
|
all.select{|o| o.is_a?(cls)}.map(&blk)
|
181
180
|
end
|
181
|
+
|
182
|
+
def data
|
183
|
+
collection? ? data_mappable : data_mappable.first
|
184
|
+
end
|
182
185
|
end
|
183
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.2
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|