json-pie 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -3
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/json/pie/resource_identity.rb +1 -2
- data/lib/json/pie/resource_object.rb +8 -1
- data/lib/json/pie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edcde33d7c1de58eea685a86544b43bcc4492abda2b9a8807efa2848afe1336d
|
4
|
+
data.tar.gz: 2882246fa32e1f7c37a250fc5ccd6fc6ecabe79965f6199256af408e92f24ff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97e5df38f0da9985fc9dad48410f8786d4d65826db6ece95e9e62a39a18591300dadab1fc995e772d3a4dac8c153d94b9a4e8c73c3b5fee99b09d96aa747fac8
|
7
|
+
data.tar.gz: 1596d7b4116c18a288932cd2cf66534c3cec05778ca24a610e879cacb9e82366cdf99a35c3d2e0db70ec36bc5fd5180c812bbe7f8230b6d0918db3fc5618f134
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Parse JSON:API data structures into Rails ActiveRecord structures.
|
4
4
|
|
5
|
+
![Tests](https://github.com/ekampp/json-pie/actions/workflows/tests.yml/badge.svg)
|
6
|
+
![Linting](https://github.com/ekampp/json-pie/actions/workflows/linting.yml/badge.svg)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
```
|
@@ -14,9 +14,8 @@ module JSON
|
|
14
14
|
def initialize(type:, id: nil, **options)
|
15
15
|
@options = options
|
16
16
|
klass = determine_type(type).to_s.classify.constantize
|
17
|
-
@instance =
|
17
|
+
@instance = klass.find_or_initialize_by klass.primary_key => id
|
18
18
|
rescue NameError
|
19
|
-
pp options
|
20
19
|
raise JSON::Pie::InvalidType, "#{type}(#{id})"
|
21
20
|
end
|
22
21
|
|
@@ -41,7 +41,7 @@ module JSON
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def assign_attributes!
|
44
|
-
instance.attributes =
|
44
|
+
instance.attributes = attributes_tuple.to_h
|
45
45
|
rescue ActiveModel::UnknownAttributeError
|
46
46
|
raise JSON::Pie::InvalidAttribute
|
47
47
|
end
|
@@ -51,6 +51,13 @@ module JSON
|
|
51
51
|
instance: instance,
|
52
52
|
relationships: data.fetch(:relationships, {})
|
53
53
|
end
|
54
|
+
|
55
|
+
def attributes_tuple
|
56
|
+
data.fetch(:attributes, {}).collect do |key, value|
|
57
|
+
key = options.dig(:attributes_map, data.fetch(:type), key).presence || key
|
58
|
+
[key, value]
|
59
|
+
end
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
data/lib/json/pie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-pie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kampp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|