jsonapi-ruby-deserializer 1.2.0 → 1.3.0
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 +8 -1
- data/lib/jsonapi-ruby-deserializer/parser.rb +18 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41a86a901f84ce048b245a96557f3df26804b66c587dd28243264ba79e4b3a18
|
4
|
+
data.tar.gz: e2686bb6a19001fe7b4bc90cf602e651e362fb31420a3858df209c924a2cb33e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d38cb44a11885ce23d7cc667c2e32e00afec66c4c1577b869e3f2ff25c8d75c03c80e42d4d6d3091a0849ef68c89fa2bac2d1a3a3791ee1dac9aca4935c4bf
|
7
|
+
data.tar.gz: 8dfc1c6ee325a9ade56d2f918952d3dd09207880af952795ea2248b244658898b6ac6f9e54567a68236cc11190606cac6ae7617c0654fa9d2823ebd9c8066325
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# JSONAPI Ruby Deserializer
|
2
|
-
Makes work with [JSON
|
2
|
+
Makes work with [JSON:API compound documents](https://jsonapi.org/format/#document-compound-documents) easy
|
3
3
|
|
4
4
|
## Status
|
5
5
|
[](https://circleci.com/gh/igatto/jsonapi-ruby-deserializer/tree/main)  
|
@@ -131,5 +131,12 @@ document.jsonapi.to_h
|
|
131
131
|
# => {"version"=>"1.0"}
|
132
132
|
```
|
133
133
|
|
134
|
+
#### Dynamic resources
|
135
|
+
```ruby
|
136
|
+
document.data[0].attributes.dynamic_key = 'dynamic_value'
|
137
|
+
document.data[0].attributes.dynamic_key
|
138
|
+
# => "dynamic_value"
|
139
|
+
```
|
140
|
+
|
134
141
|
## License
|
135
142
|
jsonapi-ruby-deserializer is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
@@ -4,15 +4,30 @@ module JSONAPI
|
|
4
4
|
module Ruby
|
5
5
|
module Deserializer
|
6
6
|
module Parser
|
7
|
-
attr_accessor :to_h
|
8
|
-
|
9
7
|
def parse!(data)
|
10
|
-
@to_h = data
|
11
8
|
data.each do |field, value|
|
12
9
|
instance_variable_set("@#{field}", value)
|
13
10
|
self.class.send(:attr_accessor, field.to_sym)
|
14
11
|
end
|
15
12
|
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
{}.tap do |h|
|
16
|
+
self.instance_variables.each do |variable|
|
17
|
+
h.merge!(variable.to_s[1..-1] => instance_variable_get(variable))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method, *args, &block)
|
23
|
+
if args.empty?
|
24
|
+
super
|
25
|
+
else
|
26
|
+
field = method[0...-1]
|
27
|
+
instance_variable_set("@#{field}", *args)
|
28
|
+
self.class.send(:attr_accessor, field.to_sym)
|
29
|
+
end
|
30
|
+
end
|
16
31
|
end
|
17
32
|
end
|
18
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-ruby-deserializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grzegorz Płóciniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.5'
|
41
|
-
description: Makes work with JSON
|
41
|
+
description: Makes work with JSON:API compound documents easy
|
42
42
|
email: grzegorzsend@gmail.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|