jsonapi-realizer 2.0.1 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e72cdbc01521b2454b71163a42709f62c44a0c68cb7278696d4b547a0d34dd9
4
- data.tar.gz: ee5ba23558d88677206bef2564735d4d0f7050366bbf23fe702bd145b4b66b90
3
+ metadata.gz: 249bd86429ad678910d08bac26aa46fc25e6d22a326aef4c613c59bb1f8d7ace
4
+ data.tar.gz: ecc579c9998df302d71287d348fa4fe83c879913520f5d939b88e57af3dd6adf
5
5
  SHA512:
6
- metadata.gz: ebd81b1e851ca61e8c1d8f29d4838b0a034b5475a18d16cd722f78a8020cb62f268d82c3d54ebcefabf3528021739698426580a5d870cd7b47fd92ceff12868b
7
- data.tar.gz: e307d10a04c8384b76687dbe353540e983d93f480d6c31664e6f9dd87869f62d903312f5fd21a04cc22758b7908eaa8f739adfc14aa98ff6ef296733e37701db
6
+ metadata.gz: e4f9fd5458983657b7ac6ad4ae84f4dcbfb00ffbb95366f4f28d180081e9a54baebd799d059be21a14aedc778eadd5113b68d5b57c48e02032b3bf05289370db
7
+ data.tar.gz: 268221f1161db90714f3c4660468948a6f30349256b2f14e22a0e65212875dfae0fef5a5b23ed7826528500bca40fb7ee6027ea9da54ab3e07e2765ccc196484
@@ -1,6 +1,8 @@
1
1
  module JSONAPI
2
2
  module Realizer
3
- class Resource
3
+ module Resource
4
+ extend ActiveSupport::Concern
5
+
4
6
  attr_reader :model
5
7
 
6
8
  def initialize(model)
@@ -31,73 +33,75 @@ module JSONAPI
31
33
  self.class.configuration
32
34
  end
33
35
 
34
- def self.attribute(name)
35
- attributes.public_send(name.to_sym)
36
- end
36
+ class_methods do
37
+ def attribute(name)
38
+ attributes.public_send(name.to_sym)
39
+ end
37
40
 
38
- def self.relationship(name)
39
- relationships.public_send(name.to_sym)
40
- end
41
+ def relationship(name)
42
+ relationships.public_send(name.to_sym)
43
+ end
41
44
 
42
- def self.valid_attribute?(name, value)
43
- attributes.respond_to?(name.to_sym)
44
- end
45
+ def valid_attribute?(name, value)
46
+ attributes.respond_to?(name.to_sym)
47
+ end
45
48
 
46
- def self.valid_relationship?(name, value)
47
- relationships.respond_to?(name.to_sym)
48
- end
49
+ def valid_relationship?(name, value)
50
+ relationships.respond_to?(name.to_sym)
51
+ end
49
52
 
50
- def self.valid_sparse_field?(name)
51
- attribute(name).fetch(:selectable)
52
- end
53
+ def valid_sparse_field?(name)
54
+ attribute(name).fetch(:selectable)
55
+ end
53
56
 
54
- def self.valid_includes?(name)
55
- relationship(name).fetch(:includable)
56
- end
57
+ def valid_includes?(name)
58
+ relationship(name).fetch(:includable)
59
+ end
57
60
 
58
- def self.has(name, selectable: true)
59
- attributes.public_send("#{name}=", OpenStruct.new({name: name, selectable: selectable}))
60
- end
61
+ def has(name, selectable: true)
62
+ attributes.public_send("#{name}=", OpenStruct.new({name: name, selectable: selectable}))
63
+ end
61
64
 
62
- def self.has_related(name, as: name, includable: true)
63
- relationships.public_send("#{name}=", OpenStruct.new({name: name, as: as, includable: includable}))
64
- end
65
+ def has_related(name, as: name, includable: true)
66
+ relationships.public_send("#{name}=", OpenStruct.new({name: name, as: as, includable: includable}))
67
+ end
65
68
 
66
- def self.has_one(name, as: name, includable: true)
67
- has_related(name, as: name, includable: includable)
68
- end
69
+ def has_one(name, as: name, includable: true)
70
+ has_related(name, as: name, includable: includable)
71
+ end
69
72
 
70
- def self.has_many(name, as: name, includable: true)
71
- has_related(name, as: name, includable: includable)
72
- end
73
+ def has_many(name, as: name, includable: true)
74
+ has_related(name, as: name, includable: includable)
75
+ end
73
76
 
74
- def self.adapter
75
- configuration.adapter
76
- end
77
+ def adapter
78
+ configuration.adapter
79
+ end
77
80
 
78
- def self.attributes
79
- configuration.attributes
80
- end
81
+ def attributes
82
+ configuration.attributes
83
+ end
81
84
 
82
- def self.relationships
83
- configuration.relationships
84
- end
85
+ def relationships
86
+ configuration.relationships
87
+ end
85
88
 
86
- def self.model_class
87
- configuration.model_class
88
- end
89
+ def model_class
90
+ configuration.model_class
91
+ end
89
92
 
90
- def self.register(type, class_name:, adapter:)
91
- JSONAPI::Realizer.register(
92
- resource_class: self,
93
- model_class: class_name.constantize,
94
- adapter: JSONAPI::Realizer::Adapter.new(adapter),
95
- type: type.to_s
96
- )
97
- end
93
+ def register(type, class_name:, adapter:)
94
+ JSONAPI::Realizer.register(
95
+ resource_class: self,
96
+ model_class: class_name.constantize,
97
+ adapter: JSONAPI::Realizer::Adapter.new(adapter),
98
+ type: type.to_s
99
+ )
100
+ end
98
101
 
99
- def self.configuration
100
- JSONAPI::Realizer.resource_mapping.fetch(self)
102
+ def configuration
103
+ JSONAPI::Realizer.resource_mapping.fetch(self)
104
+ end
101
105
  end
102
106
  end
103
107
  end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Realizer
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-realizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene