jsonapi-realizer 4.3.0 → 4.4.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: 7fd1601642408028cb8b64b1f8a9276a13e1a4bd415eba396d7241477e2c7f05
4
- data.tar.gz: f541b582a1efe495e91c34a110cc7ad937651b29043daa7c1fe5780ae814361c
3
+ metadata.gz: 6a8bebae1837baec43c16e73cc362203f65387459f992a81732d035ffdb0c61e
4
+ data.tar.gz: dad4dfe6f56dd8c85f35c9e3f829939d5278e652f7489d9a01958d15071e3aa8
5
5
  SHA512:
6
- metadata.gz: 730abd038c5ec82727e7e332b7304fb43c45bc471d84466294f0d686d32e2f2e692e5b1959f2bfe288ef5564ae7939659a9732cec4fb17dd02db4ed55820d2a5
7
- data.tar.gz: c60aa2e21f4a0e75d394e6ebcdbe46a30a00afd21cb3df6c0db6f05b759e951c643f3b3e4da38319ecb628e7984d6c3c9cc71b8c5a80bd5035036f27c188d73c
6
+ metadata.gz: 101883f640d8a56b561212abc84fd4cdf34613b41a0f14e6d8625eb6439b31c1e236eece7663366aa1ba6b7660279da05547d1f9eba9050ded2a12c04aa4fec4
7
+ data.tar.gz: cb0f5eb6555aa35c64e7b8bafbeced9bad365ff337bd26ea5a023e26e529a6ecd3b3c2f4cde93de4090f9243d31df486b28a2f59dd99c02dac73f9c6488ca60c
data/README.md CHANGED
@@ -135,7 +135,7 @@ class PhotosController < ApplicationController
135
135
  policy(Photo).sanitize(:index, params),
136
136
  headers: request.headers,
137
137
  type: :posts,
138
- relation: policy_scope(Photo)
138
+ scope: policy_scope(Photo)
139
139
  )
140
140
 
141
141
  # See: pundit for `authorize()`
@@ -13,26 +13,6 @@ module JSONAPI
13
13
  require_relative "realizer/adapter"
14
14
  require_relative "realizer/resource"
15
15
 
16
- def self.register(resource_class:, model_class:, adapter:, type:)
17
- @mapping ||= Set.new
18
- @mapping << OpenStruct.new({
19
- resource_class: resource_class,
20
- model_class: model_class,
21
- adapter: adapter,
22
- type: type.dasherize,
23
- attributes: OpenStruct.new({}),
24
- relationships: OpenStruct.new({})
25
- })
26
- end
27
-
28
- def self.resource_mapping
29
- @mapping.index_by(&:resource_class)
30
- end
31
-
32
- def self.type_mapping
33
- @mapping.index_by(&:type)
34
- end
35
-
36
16
  def self.create(payload, headers:, scope: nil)
37
17
  enact(Action::Create.new(payload: payload, headers: headers, scope: scope))
38
18
  end
@@ -94,7 +94,7 @@ module JSONAPI
94
94
  end
95
95
  else
96
96
  data = value.fetch("data")
97
- mapping = JSONAPI::Realizer.type_mapping.fetch(data.fetch("type"))
97
+ mapping = JSONAPI::Realizer::Resource.type_mapping.fetch(data.fetch("type"))
98
98
  mapping.adapter.find_via_call(
99
99
  mapping.model_class,
100
100
  data.fetch("id")
@@ -120,7 +120,7 @@ module JSONAPI
120
120
  chain.reduce(resource_class) do |last_resource_class, key|
121
121
  break unless last_resource_class
122
122
 
123
- JSONAPI::Realizer.type_mapping.fetch(last_resource_class.relationship(key).as).resource_class if last_resource_class.valid_includes?(key)
123
+ JSONAPI::Realizer::Resource.type_mapping.fetch(last_resource_class.relationship(key).as).resource_class if last_resource_class.valid_includes?(key)
124
124
  end
125
125
  end
126
126
  # [["carts", "cart_items", "product"], ["payments"]]
@@ -145,7 +145,7 @@ module JSONAPI
145
145
  break unless last_resource_class
146
146
 
147
147
  if last_resource_class.valid_includes?(key)
148
- JSONAPI::Realizer.type_mapping.fetch(last_resource_class.relationship(key).as).resource_class
148
+ JSONAPI::Realizer::Resource.type_mapping.fetch(last_resource_class.relationship(key).as).resource_class
149
149
  elsif last_resource_class.valid_sparse_field?(key)
150
150
  last_resource_class
151
151
  end
@@ -155,7 +155,7 @@ module JSONAPI
155
155
  end
156
156
 
157
157
  private def configuration
158
- JSONAPI::Realizer.type_mapping.fetch(type) if type
158
+ JSONAPI::Realizer::Resource.type_mapping.fetch(type) if type
159
159
  end
160
160
  end
161
161
  end
@@ -1,30 +1,4 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe JSONAPI::Realizer::Adapter do
4
- describe ".adapt" do
5
- context "for the active_record mapped alias" do
6
- it "defines the find_via_call instance variable as a anonymous function"
7
- it "defines the find_via_call instance variable as a anonymous function"
8
- end
9
-
10
- context "for a mapped alias that doesn't exist" do
11
-
12
- end
13
-
14
- context "for a block defintion" do
15
-
16
- end
17
-
18
- context "for an alias and block defintion" do
19
-
20
- end
21
-
22
- context "when the find_via interface isn't defined" do
23
-
24
- end
25
-
26
- context "when the assign_attributes_via interface isn't defined" do
27
-
28
- end
29
- end
30
4
  end
@@ -9,6 +9,7 @@ module JSONAPI
9
9
  require_relative "error/missing_content_type_header"
10
10
  require_relative "error/missing_root_property"
11
11
  require_relative "error/missing_type_resource_property"
12
+ require_relative "error/duplicate_registration"
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,9 @@
1
+ module JSONAPI
2
+ module Realizer
3
+ class Error
4
+ class DuplicateRegistration < Error
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -5,6 +5,27 @@ module JSONAPI
5
5
 
6
6
  attr_reader :model
7
7
 
8
+ def self.register(resource_class:, model_class:, adapter:, type:)
9
+ @mapping ||= Set.new
10
+ raise JSONAPI::Realizer::Error::DuplicateRegistration if @mapping.any? { |realizer| realizer.type == type }
11
+ @mapping << OpenStruct.new({
12
+ resource_class: resource_class,
13
+ model_class: model_class,
14
+ adapter: adapter,
15
+ type: type.dasherize,
16
+ attributes: OpenStruct.new({}),
17
+ relationships: OpenStruct.new({})
18
+ })
19
+ end
20
+
21
+ def self.resource_mapping
22
+ @mapping.index_by(&:resource_class)
23
+ end
24
+
25
+ def self.type_mapping
26
+ @mapping.index_by(&:type)
27
+ end
28
+
8
29
  def initialize(model)
9
30
  @model = model
10
31
  end
@@ -91,7 +112,7 @@ module JSONAPI
91
112
  end
92
113
 
93
114
  def register(type, class_name:, adapter:)
94
- JSONAPI::Realizer.register(
115
+ JSONAPI::Realizer::Resource.register(
95
116
  resource_class: self,
96
117
  model_class: class_name.constantize,
97
118
  adapter: JSONAPI::Realizer::Adapter.new(adapter),
@@ -100,7 +121,7 @@ module JSONAPI
100
121
  end
101
122
 
102
123
  def configuration
103
- JSONAPI::Realizer.resource_mapping.fetch(self)
124
+ JSONAPI::Realizer::Resource.resource_mapping.fetch(self)
104
125
  end
105
126
  end
106
127
  end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe JSONAPI::Realizer do
4
+ describe ".register" do
5
+ subject {JSONAPI::Realizer::Resource.register(resource_class: "Test", model_class: "test", adapter: :a, type: "a")}
6
+ context "with something already owning that type" do
7
+ before do
8
+ JSONAPI::Realizer::Resource.register(resource_class: "Test", model_class: "test", adapter: :a, type: "a")
9
+ end
10
+
11
+ it "raises an exception" do
12
+ expect {subject}.to(raise_exception(JSONAPI::Realizer::Error::DuplicateRegistration))
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Realizer
3
- VERSION = "4.3.0"
3
+ VERSION = "4.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-realizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,6 +204,7 @@ files:
204
204
  - lib/jsonapi/realizer/adapter/memory.rb
205
205
  - lib/jsonapi/realizer/adapter_spec.rb
206
206
  - lib/jsonapi/realizer/error.rb
207
+ - lib/jsonapi/realizer/error/duplicate_registration.rb
207
208
  - lib/jsonapi/realizer/error/include_without_data_property.rb
208
209
  - lib/jsonapi/realizer/error/invalid_accept_header.rb
209
210
  - lib/jsonapi/realizer/error/invalid_content_type_header.rb
@@ -213,6 +214,7 @@ files:
213
214
  - lib/jsonapi/realizer/error/missing_root_property.rb
214
215
  - lib/jsonapi/realizer/error/missing_type_resource_property.rb
215
216
  - lib/jsonapi/realizer/resource.rb
217
+ - lib/jsonapi/realizer/resource_spec.rb
216
218
  - lib/jsonapi/realizer/version.rb
217
219
  - lib/jsonapi/realizer/version_spec.rb
218
220
  - lib/jsonapi/realizer_spec.rb