jsonapi_deserializer 1.3.0 → 1.3.1
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/README.md +13 -0
- data/jsonapi_deserializer.gemspec +1 -0
- data/lib/jsonapi_deserializer/configuration.rb +23 -0
- data/lib/jsonapi_deserializer/version.rb +1 -1
- data/lib/jsonapi_deserializer.rb +8 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7cdae31765c3a976edac1f14e45aed9c05aa824fe59cc551355748ec5033ada
|
4
|
+
data.tar.gz: 9b19152a529e0ec488c3aad1f14dee437d254a2123e5f3229dfec0a03c567306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3d041f8ee139429d98156b61ac942bbded37651eba0b55837471d9ce060fce4d9508ff398b2b631b7fba45c18884f3dcc1f8f26c2472013407c69b439f9a25
|
7
|
+
data.tar.gz: bf0b3d7db9ba4889ab9d736926d14870d2c17dfd311fba03dde8da2a4f4b962b792bb12edd3e63a816ed69586016c41be76b7242c1696820da7a29a6163093d3
|
data/README.md
CHANGED
@@ -38,6 +38,19 @@ one_deserialized = JSONApi::Deserializer.new(response).deserialized_hash
|
|
38
38
|
# one_deserialized.name == 'fluffy'
|
39
39
|
```
|
40
40
|
|
41
|
+
## Configuration
|
42
|
+
|
43
|
+
Version 1.3.1 introduces the ability to configure the gem using an initializer file and block with following options:
|
44
|
+
|
45
|
+
```
|
46
|
+
JSONApi::Deserializer.configure do |config|
|
47
|
+
config.supports_lids = true
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Above are all options for configuration with the default of each configuration option.
|
52
|
+
|
53
|
+
`supports_lids` - will include a `lid` key in each deserialized hash record. See JSONAPI spec '> 1.1' for more information on lids.
|
41
54
|
|
42
55
|
## Development
|
43
56
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module JSONApi
|
2
|
+
class Deserializer
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :support_lids
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@support_lids = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/jsonapi_deserializer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
3
|
require 'jsonapi_deserializer/version'
|
4
|
+
require 'jsonapi_deserializer/configuration'
|
4
5
|
|
5
6
|
module JSONApi
|
6
7
|
class Deserializer
|
@@ -70,6 +71,7 @@ module JSONApi
|
|
70
71
|
|
71
72
|
def deserialized_hash
|
72
73
|
data = @response[:data]
|
74
|
+
|
73
75
|
if data.is_a? Array
|
74
76
|
data.map { |datum| @store.get(datum[:type], datum[:id], datum[:lid]) }
|
75
77
|
else
|
@@ -81,7 +83,12 @@ module JSONApi
|
|
81
83
|
|
82
84
|
def store_records(data)
|
83
85
|
data.each do |datum|
|
84
|
-
record =
|
86
|
+
record = if self.class.configuration.support_lids
|
87
|
+
Record.new(id: datum[:id], lid: datum[:lid]).merge(datum[:attributes] || {})
|
88
|
+
else
|
89
|
+
Record.new(id: datum[:id]).merge(datum[:attributes] || {})
|
90
|
+
end
|
91
|
+
|
85
92
|
@store.set(datum[:type], datum[:id], datum[:lid], record)
|
86
93
|
end
|
87
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_deserializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trek Glowacki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- bin/setup
|
106
106
|
- jsonapi_deserializer.gemspec
|
107
107
|
- lib/jsonapi_deserializer.rb
|
108
|
+
- lib/jsonapi_deserializer/configuration.rb
|
108
109
|
- lib/jsonapi_deserializer/version.rb
|
109
110
|
homepage: https://github.com/PopularPays/jsonapi_deserializer
|
110
111
|
licenses:
|