jsonapi_mapper 0.1.2 → 0.1.3

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: 46a0f72ab5eea90edcef9d6851bb26627dcb5af1
4
- data.tar.gz: 74101764b455c9fb85a96894288b15f4046f9120
3
+ metadata.gz: 47223d6620e9fc3fff6740ffc29ab2667b18e2b8
4
+ data.tar.gz: a8453219e94d3fb0f412f4c64256ce8e563fb399
5
5
  SHA512:
6
- metadata.gz: 23be03d8e041f8b2f034e0f33dfff5c76f053bc99e78e1a88c4ed23d34826db9a38262869653d21a984521d8fa923b824f016f19e031959714b97d8f76b58940
7
- data.tar.gz: 66493bd24c24da648b0d21c701a3fd5c18653c2769af2d6621bf91c579e06b643e2cf128a4a491a64ace29950a3449b978c05c82d6ae8a2c3d47e49a4b2d4ad9
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's always an array, even if the document had a single resource.
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
@@ -1,3 +1,3 @@
1
1
  module JsonapiMapper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -18,7 +18,7 @@ module JsonapiMapper
18
18
 
19
19
  class DocumentMapper
20
20
  attr_accessor :document, :unscoped, :types, :renames, :resources,
21
- :included, :data_mappable
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 data_mappable = self.document[:data]
31
- if data_mappable.is_a?(Array)
32
- data_mappable.map{|r| build_resource(r) }.compact
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
- [ build_resource(data_mappable) ].compact
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.data_mappable = main.try(:map, &:object) || []
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
- data_mappable.size > 1
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 data
183
- collection? ? data_mappable : data_mappable.first
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.2
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-29 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport