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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8da746332e94869adf5d9637999866f05c4b2c0a
4
- data.tar.gz: ef0dd97cc32c359b48d62e5f6de88ca36e95f630
3
+ metadata.gz: 46a0f72ab5eea90edcef9d6851bb26627dcb5af1
4
+ data.tar.gz: 74101764b455c9fb85a96894288b15f4046f9120
5
5
  SHA512:
6
- metadata.gz: 6401a0a6a12a03c4874fcac5ef69aa9b89a3449b31265448e5092b2b75c2d912ff87d672155c426e38ec300b6af784279db7e2e7e9b3948a4b1a2dde90098730
7
- data.tar.gz: a6d2495852c6ce11489138bc779a1eab3b67741b05981ff58328f1e5d7c41be94f218a950a4b3a3e2c664c484cf5b36a5efb41046d19b4d44bf2df473d13d4f6
6
+ metadata.gz: 23be03d8e041f8b2f034e0f33dfff5c76f053bc99e78e1a88c4ed23d34826db9a38262869653d21a984521d8fa923b824f016f19e031959714b97d8f76b58940
7
+ data.tar.gz: 66493bd24c24da648b0d21c701a3fd5c18653c2769af2d6621bf91c579e06b643e2cf128a4a491a64ace29950a3449b978c05c82d6ae8a2c3d47e49a4b2d4ad9
@@ -1,3 +1,3 @@
1
1
  module JsonapiMapper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -18,21 +18,20 @@ module JsonapiMapper
18
18
 
19
19
  class DocumentMapper
20
20
  attr_accessor :document, :unscoped, :types, :renames, :resources,
21
- :data, :included
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 data = self.document[:data]
32
- if data.is_a?(Array)
33
- data.map{|r| build_resource(r) }.compact
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(data) ].compact
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.data = main.try(:map, &:object) || []
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
- (data + included)
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
- data.size > 1
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
- data.select{|o| o.is_a?(cls)}.map(&blk)
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.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-28 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport