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: 9556e194a2e69b081bad43a8ddfbab23c55b9707a2250598222854943118b50c
4
- data.tar.gz: 14653444ae546e3f3ecb4a4611b9739e247538b82d032a475b7931fe8a97f2ef
3
+ metadata.gz: c287ea52f8d9f995a5c91f7e50f6cba792bc4ca365e8ef812d7a469a1a61d194
4
+ data.tar.gz: 72cc3904868b56e90520245a839c269115a6dc506f8f06314f9315eac328657f
5
5
  SHA512:
6
- metadata.gz: a0985c0cfcbdab3e5c6d6115838a3f30699e40a819cd4c00c2a58b9bf27181e5d5bce12d4da230e6d2c3ba9564df9e04a777a5086e5074c1bf6b757ff7b8d456
7
- data.tar.gz: 82e6d60d6806c0d37c043bbe16783dacb9601eb9651c200decf078efc012292d87d36a605b55697e8c6ef8afeb0bc03bf300eca8104b1e707aadc4f18438e0d9
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
- if fetch_relation(subject).present?
41
- materializer_class.new(
42
- **subject.raw,
43
- object: fetch_relation(subject)
44
- )
45
- end
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
- @fetch_relationship ||= {}
63
- @fetch_relationship[checksum(subject)] ||= subject.object.public_send(from)
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: exposed(relations)
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
- }.transform_values(&:presence).compact
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
- data: as_data,
66
- included:
67
- }.transform_values(&:presence).compact
69
+ # TODO: Add more links
70
+ }
71
+ )
68
72
  end
69
73
 
70
74
  def type
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JSONAPI
4
4
  module Materializer
5
- VERSION = "2.0.0"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
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: 2.0.0
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-10-27 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport