jsonapi-realizer 4.4.0 → 5.0.0
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 +4 -4
- data/README.md +13 -104
- data/lib/jsonapi/realizer.rb +26 -25
- data/lib/jsonapi/realizer/action.rb +2 -2
- data/lib/jsonapi/realizer/adapter.rb +21 -58
- data/lib/jsonapi/realizer/adapter/active_record.rb +38 -17
- data/lib/jsonapi/realizer/adapter_spec.rb +3 -2
- data/lib/jsonapi/realizer/configuration.rb +22 -0
- data/lib/jsonapi/realizer/context.rb +8 -0
- data/lib/jsonapi/realizer/controller.rb +55 -0
- data/lib/jsonapi/realizer/error.rb +10 -9
- data/lib/jsonapi/realizer/error/invalid_content_type_header.rb +5 -0
- data/lib/jsonapi/realizer/error/invalid_data_type_property.rb +13 -0
- data/lib/jsonapi/realizer/error/invalid_root_property.rb +13 -0
- data/lib/jsonapi/realizer/error/{duplicate_registration.rb → missing_data_type_property.rb} +1 -1
- data/lib/jsonapi/realizer/error/resource_attribute_not_found.rb +14 -0
- data/lib/jsonapi/realizer/error/resource_relationship_not_found.rb +14 -0
- data/lib/jsonapi/realizer/resource.rb +278 -73
- data/lib/jsonapi/realizer/resource/attribute.rb +23 -0
- data/lib/jsonapi/realizer/resource/configuration.rb +27 -0
- data/lib/jsonapi/realizer/resource/relation.rb +31 -0
- data/lib/jsonapi/realizer/resource_spec.rb +55 -8
- data/lib/jsonapi/realizer/version.rb +1 -1
- data/lib/jsonapi/realizer_spec.rb +22 -119
- metadata +70 -20
- data/lib/jsonapi/realizer/action/create.rb +0 -36
- data/lib/jsonapi/realizer/action/create_spec.rb +0 -165
- data/lib/jsonapi/realizer/action/destroy.rb +0 -27
- data/lib/jsonapi/realizer/action/destroy_spec.rb +0 -81
- data/lib/jsonapi/realizer/action/index.rb +0 -29
- data/lib/jsonapi/realizer/action/index_spec.rb +0 -75
- data/lib/jsonapi/realizer/action/show.rb +0 -35
- data/lib/jsonapi/realizer/action/show_spec.rb +0 -81
- data/lib/jsonapi/realizer/action/update.rb +0 -37
- data/lib/jsonapi/realizer/action/update_spec.rb +0 -170
- data/lib/jsonapi/realizer/action_spec.rb +0 -46
- data/lib/jsonapi/realizer/adapter/memory.rb +0 -31
- data/lib/jsonapi/realizer/error/invalid_accept_header.rb +0 -9
- data/lib/jsonapi/realizer/error/malformed_data_root_property.rb +0 -9
- data/lib/jsonapi/realizer/error/missing_accept_header.rb +0 -9
- data/lib/jsonapi/realizer/error/missing_type_resource_property.rb +0 -9
@@ -0,0 +1,23 @@
|
|
1
|
+
module JSONAPI
|
2
|
+
module Realizer
|
3
|
+
module Resource
|
4
|
+
class Attribute
|
5
|
+
include(ActiveModel::Model)
|
6
|
+
|
7
|
+
attr_accessor(:owner)
|
8
|
+
attr_accessor(:name)
|
9
|
+
attr_accessor(:as)
|
10
|
+
|
11
|
+
validates_presence_of(:owner)
|
12
|
+
validates_presence_of(:name)
|
13
|
+
validates_presence_of(:as)
|
14
|
+
|
15
|
+
def initialize(**keyword_arguments)
|
16
|
+
super(**keyword_arguments)
|
17
|
+
|
18
|
+
validate!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module JSONAPI
|
2
|
+
module Realizer
|
3
|
+
module Resource
|
4
|
+
class Configuration
|
5
|
+
include(ActiveModel::Model)
|
6
|
+
|
7
|
+
attr_accessor(:owner)
|
8
|
+
attr_accessor(:type)
|
9
|
+
attr_accessor(:model_class)
|
10
|
+
attr_accessor(:adapter)
|
11
|
+
attr_accessor(:attributes)
|
12
|
+
attr_accessor(:relations)
|
13
|
+
|
14
|
+
validates_presence_of(:owner)
|
15
|
+
validates_presence_of(:type)
|
16
|
+
validates_presence_of(:adapter)
|
17
|
+
validates_presence_of(:model_class)
|
18
|
+
|
19
|
+
def initialize(**keyword_arguments)
|
20
|
+
super(**keyword_arguments)
|
21
|
+
|
22
|
+
validate!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module JSONAPI
|
2
|
+
module Realizer
|
3
|
+
module Resource
|
4
|
+
class Relation
|
5
|
+
include(ActiveModel::Model)
|
6
|
+
|
7
|
+
attr_accessor(:owner)
|
8
|
+
attr_accessor(:name)
|
9
|
+
attr_accessor(:type)
|
10
|
+
attr_accessor(:as)
|
11
|
+
attr_accessor(:realizer_class_name)
|
12
|
+
|
13
|
+
validates_presence_of(:owner)
|
14
|
+
validates_presence_of(:name)
|
15
|
+
validates_presence_of(:type)
|
16
|
+
validates_presence_of(:as)
|
17
|
+
validates_presence_of(:realizer_class_name)
|
18
|
+
|
19
|
+
def initialize(**keyword_arguments)
|
20
|
+
super(**keyword_arguments)
|
21
|
+
|
22
|
+
validate!
|
23
|
+
end
|
24
|
+
|
25
|
+
def realizer_class
|
26
|
+
realizer_class_name.constantize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,15 +1,62 @@
|
|
1
|
-
require
|
1
|
+
require("spec_helper")
|
2
|
+
|
3
|
+
RSpec.describe(JSONAPI::Realizer::Resource) do
|
4
|
+
let(:resource_class) {PhotoRealizer}
|
5
|
+
let(:resource) {resource_class.new(intent: intent, parameters: parameters, headers: headers)}
|
6
|
+
|
7
|
+
describe "#as_native" do
|
8
|
+
let(:subject) {resource}
|
9
|
+
|
10
|
+
context "when accepting the right type, when creating with data, with spares fields, and includes" do
|
11
|
+
let(:intent) {:create}
|
12
|
+
let(:parameters) do
|
13
|
+
{
|
14
|
+
"include" => "photographer",
|
15
|
+
"fields" => {
|
16
|
+
"articles" => "title,body,sub-text",
|
17
|
+
"people" => "name"
|
18
|
+
},
|
19
|
+
"data" => {
|
20
|
+
"type" => "photos",
|
21
|
+
"attributes" => {
|
22
|
+
"title" => "Ember Hamster",
|
23
|
+
"src" => "http://example.com/images/productivity.png"
|
24
|
+
},
|
25
|
+
"relationships" => {
|
26
|
+
"photographer" => {
|
27
|
+
"data" => {
|
28
|
+
"type" => "people",
|
29
|
+
"id" => "9"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
let(:headers) do
|
37
|
+
{
|
38
|
+
"Accept" => "application/vnd.api+json",
|
39
|
+
"Content-Type" => "application/vnd.api+json"
|
40
|
+
}
|
41
|
+
end
|
2
42
|
|
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
43
|
before do
|
8
|
-
|
44
|
+
Account.create!(:id => 9, :name => "Dan Gebhardt", :twitter => "dgeb")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "object is a Photo" do
|
48
|
+
expect(subject.object).to be_kind_of(Photo)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "object isn't saved" do
|
52
|
+
expect(subject.object).to_not be_persisted()
|
9
53
|
end
|
10
54
|
|
11
|
-
it "
|
12
|
-
expect
|
55
|
+
it "object has the right attributes" do
|
56
|
+
expect(subject.object).to have_attributes(
|
57
|
+
:title => "Ember Hamster",
|
58
|
+
:src => "http://example.com/images/productivity.png"
|
59
|
+
)
|
13
60
|
end
|
14
61
|
end
|
15
62
|
end
|
@@ -1,126 +1,29 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe JSONAPI::Realizer do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"Content-Type" => "application/vnd.api+json",
|
18
|
-
"Accept" => "application/vnd.api+json"
|
19
|
-
}
|
20
|
-
end
|
21
|
-
let(:type) do
|
22
|
-
:photos
|
23
|
-
end
|
24
|
-
|
25
|
-
before do
|
26
|
-
Photo::STORE["550e8400-e29b-41d4-a716-446655440000"] = {
|
27
|
-
id: "550e8400-e29b-41d4-a716-446655440000",
|
28
|
-
title: "Ember Hamster",
|
29
|
-
src: "http://example.com/images/productivity.png"
|
30
|
-
}
|
31
|
-
Photo::STORE["d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"] = {
|
32
|
-
id: "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed",
|
33
|
-
title: "Ember Fox",
|
34
|
-
src: "http://example.com/images/productivity-2.png"
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
it "returns an action that has N models" do
|
39
|
-
expect(subject).to have_attributes(models: [a_kind_of(Photo), a_kind_of(Photo)])
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe ".show" do
|
45
|
-
subject { JSONAPI::Realizer.show(payload, headers: headers, type: type) }
|
46
|
-
|
47
|
-
context "with no top-level data and good headers"
|
48
|
-
context "with no top-level data and bad headers"
|
49
|
-
context "with a good payload and bad headers"
|
50
|
-
|
51
|
-
context "with a good payload and good headers" do
|
52
|
-
let(:payload) do
|
53
|
-
{
|
54
|
-
"id" => "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"
|
55
|
-
}
|
56
|
-
end
|
57
|
-
let(:headers) do
|
58
|
-
{
|
59
|
-
"Content-Type" => "application/vnd.api+json",
|
60
|
-
"Accept" => "application/vnd.api+json"
|
61
|
-
}
|
62
|
-
end
|
63
|
-
let(:type) do
|
64
|
-
:photos
|
65
|
-
end
|
66
|
-
|
67
|
-
before do
|
68
|
-
Photo::STORE["d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"] = {
|
69
|
-
id: "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed",
|
70
|
-
title: "Ember Fox",
|
71
|
-
src: "http://example.com/images/productivity-2.png"
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns an action that a model" do
|
76
|
-
expect(subject).to have_attributes(model: a_kind_of(Photo))
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe ".create" do
|
82
|
-
subject { JSONAPI::Realizer.create(payload, headers: headers) }
|
83
|
-
|
84
|
-
context "with no top-level data and good headers"
|
85
|
-
context "with no top-level data and bad headers"
|
86
|
-
context "with a good payload and bad headers"
|
87
|
-
|
88
|
-
context "with a good payload and good headers" do
|
89
|
-
let(:payload) do
|
90
|
-
{
|
91
|
-
"data" => {
|
92
|
-
"id" => "550e8400-e29b-41d4-a716-446655440000",
|
93
|
-
"type" => "photos",
|
94
|
-
"attributes" => {
|
95
|
-
"title" => "Ember Hamster",
|
96
|
-
"alt-text" => "A hamster logo.",
|
97
|
-
"src" => "http://example.com/images/productivity.png"
|
98
|
-
},
|
99
|
-
"relationships" => {
|
100
|
-
"active-photographer" => {
|
101
|
-
"data" => { "type" => "photographer-accounts", "id" => "4b8a0af6-953d-4729-8b9a-1fa4eb18f3c9" }
|
102
|
-
}
|
4
|
+
let(:parameters) {
|
5
|
+
{
|
6
|
+
"data" => {
|
7
|
+
"type" => "photos",
|
8
|
+
"attributes" => {
|
9
|
+
"title" => "Ember Hamster",
|
10
|
+
"src" => "http://example.com/images/productivity.png"
|
11
|
+
},
|
12
|
+
"relationships" => {
|
13
|
+
"photographer" => {
|
14
|
+
"data" => {
|
15
|
+
"type" => "people",
|
16
|
+
"id" => "9"
|
103
17
|
}
|
104
18
|
}
|
105
19
|
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
Account::STORE["4b8a0af6-953d-4729-8b9a-1fa4eb18f3c9"] = {
|
116
|
-
id: "4b8a0af6-953d-4729-8b9a-1fa4eb18f3c9",
|
117
|
-
name: "Kurtis Rainbolt-Greene"
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns an action that a model" do
|
122
|
-
expect(subject).to have_attributes(model: a_kind_of(Photo))
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
let(:headers) {
|
24
|
+
{
|
25
|
+
"Accept" => "application/vnd.api+json",
|
26
|
+
"Content-Type" => "application/vnd.api+json"
|
27
|
+
}
|
28
|
+
}
|
126
29
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-realizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.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-
|
11
|
+
date: 2018-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: activemodel
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +172,20 @@ dependencies:
|
|
144
172
|
- - "~>"
|
145
173
|
- !ruby/object:Gem::Version
|
146
174
|
version: '0.11'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: addressable
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '2.5'
|
182
|
+
type: :runtime
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '2.5'
|
147
189
|
- !ruby/object:Gem::Dependency
|
148
190
|
name: activesupport
|
149
191
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +218,20 @@ dependencies:
|
|
176
218
|
- - ">="
|
177
219
|
- !ruby/object:Gem::Version
|
178
220
|
version: '5.1'
|
221
|
+
- !ruby/object:Gem::Dependency
|
222
|
+
name: kaminari
|
223
|
+
requirement: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - "~>"
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '1.1'
|
228
|
+
type: :runtime
|
229
|
+
prerelease: false
|
230
|
+
version_requirements: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - "~>"
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '1.1'
|
179
235
|
description: A way to take json:api requests and turn them into models
|
180
236
|
email:
|
181
237
|
- kurtis@rainbolt-greene.online
|
@@ -188,32 +244,26 @@ files:
|
|
188
244
|
- lib/jsonapi-realizer.rb
|
189
245
|
- lib/jsonapi/realizer.rb
|
190
246
|
- lib/jsonapi/realizer/action.rb
|
191
|
-
- lib/jsonapi/realizer/action/create.rb
|
192
|
-
- lib/jsonapi/realizer/action/create_spec.rb
|
193
|
-
- lib/jsonapi/realizer/action/destroy.rb
|
194
|
-
- lib/jsonapi/realizer/action/destroy_spec.rb
|
195
|
-
- lib/jsonapi/realizer/action/index.rb
|
196
|
-
- lib/jsonapi/realizer/action/index_spec.rb
|
197
|
-
- lib/jsonapi/realizer/action/show.rb
|
198
|
-
- lib/jsonapi/realizer/action/show_spec.rb
|
199
|
-
- lib/jsonapi/realizer/action/update.rb
|
200
|
-
- lib/jsonapi/realizer/action/update_spec.rb
|
201
|
-
- lib/jsonapi/realizer/action_spec.rb
|
202
247
|
- lib/jsonapi/realizer/adapter.rb
|
203
248
|
- lib/jsonapi/realizer/adapter/active_record.rb
|
204
|
-
- lib/jsonapi/realizer/adapter/memory.rb
|
205
249
|
- lib/jsonapi/realizer/adapter_spec.rb
|
250
|
+
- lib/jsonapi/realizer/configuration.rb
|
251
|
+
- lib/jsonapi/realizer/context.rb
|
252
|
+
- lib/jsonapi/realizer/controller.rb
|
206
253
|
- lib/jsonapi/realizer/error.rb
|
207
|
-
- lib/jsonapi/realizer/error/duplicate_registration.rb
|
208
254
|
- lib/jsonapi/realizer/error/include_without_data_property.rb
|
209
|
-
- lib/jsonapi/realizer/error/invalid_accept_header.rb
|
210
255
|
- lib/jsonapi/realizer/error/invalid_content_type_header.rb
|
211
|
-
- lib/jsonapi/realizer/error/
|
212
|
-
- lib/jsonapi/realizer/error/
|
256
|
+
- lib/jsonapi/realizer/error/invalid_data_type_property.rb
|
257
|
+
- lib/jsonapi/realizer/error/invalid_root_property.rb
|
213
258
|
- lib/jsonapi/realizer/error/missing_content_type_header.rb
|
259
|
+
- lib/jsonapi/realizer/error/missing_data_type_property.rb
|
214
260
|
- lib/jsonapi/realizer/error/missing_root_property.rb
|
215
|
-
- lib/jsonapi/realizer/error/
|
261
|
+
- lib/jsonapi/realizer/error/resource_attribute_not_found.rb
|
262
|
+
- lib/jsonapi/realizer/error/resource_relationship_not_found.rb
|
216
263
|
- lib/jsonapi/realizer/resource.rb
|
264
|
+
- lib/jsonapi/realizer/resource/attribute.rb
|
265
|
+
- lib/jsonapi/realizer/resource/configuration.rb
|
266
|
+
- lib/jsonapi/realizer/resource/relation.rb
|
217
267
|
- lib/jsonapi/realizer/resource_spec.rb
|
218
268
|
- lib/jsonapi/realizer/version.rb
|
219
269
|
- lib/jsonapi/realizer/version_spec.rb
|
@@ -238,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
288
|
version: '0'
|
239
289
|
requirements: []
|
240
290
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.7.
|
291
|
+
rubygems_version: 2.7.7
|
242
292
|
signing_key:
|
243
293
|
specification_version: 4
|
244
294
|
summary: A way to take json:api requests and turn them into models
|