jsonapi-materializer 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c287ea52f8d9f995a5c91f7e50f6cba792bc4ca365e8ef812d7a469a1a61d194
|
4
|
+
data.tar.gz: 72cc3904868b56e90520245a839c269115a6dc506f8f06314f9315eac328657f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 544c4346e3d48c094efae3c518fcf3cb7dbd692b37b876a1e2cfc77d2af256ce07441999f207b9ca336e19621a44a5fdfe02358f88907b17c5949e613358f041
|
7
|
+
data.tar.gz: 34f5d566e30b8ac81fff03976c4a16a48cffdeaa858295553d12a051e936e79b273c4d42c77272c4d76b5f02009fa78987255f2b83422a793c2978fa0011ec77
|
@@ -37,12 +37,12 @@ module JSONAPI
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
when :one
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
)
|
45
|
-
|
40
|
+
raise StandardError, "couldn't find a relationship by the name #{from} on #{subject.class}" unless fetch_relation(subject).present?
|
41
|
+
|
42
|
+
materializer_class.new(
|
43
|
+
**subject.raw,
|
44
|
+
object: fetch_relation(subject)
|
45
|
+
)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -59,8 +59,8 @@ module JSONAPI
|
|
59
59
|
end
|
60
60
|
|
61
61
|
private def fetch_relation(subject)
|
62
|
-
@
|
63
|
-
@
|
62
|
+
@fetch_relationships ||= {}
|
63
|
+
@fetch_relationships[checksum(subject)] ||= subject.object.public_send(from)
|
64
64
|
end
|
65
65
|
|
66
66
|
private def materializer_class
|
@@ -44,27 +44,31 @@ module JSONAPI
|
|
44
44
|
|
45
45
|
def as_data
|
46
46
|
{
|
47
|
-
id:,
|
48
|
-
type:,
|
49
47
|
attributes: exposed(attributes.except(:id))
|
50
48
|
.transform_values { |attribute| object.public_send(attribute.from) },
|
51
|
-
relationships:
|
52
|
-
.transform_values { |relation| relation.using(self).as_json }
|
49
|
+
relationships: relations
|
50
|
+
.transform_values { |relation| relation.using(self).as_json }
|
51
|
+
}.transform_values(&:presence).compact.merge(
|
52
|
+
id:,
|
53
|
+
type:,
|
53
54
|
links: {
|
54
55
|
self: links_self
|
56
|
+
# TODO: Add more links
|
55
57
|
}
|
56
|
-
|
58
|
+
)
|
57
59
|
end
|
58
60
|
# rubocop:enable Metrics/AbcSize
|
59
61
|
|
60
62
|
def as_json(*)
|
61
63
|
{
|
64
|
+
included:
|
65
|
+
}.transform_values(&:presence).compact.merge(
|
66
|
+
data: as_data,
|
62
67
|
links: {
|
63
68
|
self: links_self
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
}.transform_values(&:presence).compact
|
69
|
+
# TODO: Add more links
|
70
|
+
}
|
71
|
+
)
|
68
72
|
end
|
69
73
|
|
70
74
|
def type
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-materializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|