jsonapi_actions 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +91 -75
- data/README.md +5 -6
- data/jsonapi_actions.gemspec +4 -4
- data/lib/jsonapi_actions.rb +22 -11
- data/lib/jsonapi_actions/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd75b7ea62934cf27cc351d4327cf302af2ab1f5aed66d6d6075575e974d90b6
|
4
|
+
data.tar.gz: 56008596f5f59e8eb0640b2d0be4b81eed49dd6fdc7e0f08af5d9f10fc683687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 709f2ae770a5efbfca5252997c866205a898eb85cc77dddc5517a936d99910e169f7767ecd1a677ec33b4aef30157236528260e9d629cb937578250fb489350b
|
7
|
+
data.tar.gz: 47e353f3fa687d0ee7a8463dfa412b110982bfcf10c2f294084603bce6f12d29ae937befb795549be5b3bc36f59ce2c9a2f85c4368a2c0a217a57c79159f93c5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.2.2] - 2020-05-18
|
8
|
+
### Fixed
|
9
|
+
- JsonapiActions#json_response uses `defined?` to check for serializer library
|
data/Gemfile.lock
CHANGED
@@ -1,119 +1,134 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jsonapi_actions (0.1.
|
4
|
+
jsonapi_actions (0.1.2)
|
5
5
|
kaminari (>= 1.0, < 2.0)
|
6
|
-
rails (>= 4.0, <
|
6
|
+
rails (>= 4.0, < 7.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (
|
12
|
-
actionpack (=
|
11
|
+
actioncable (6.0.2.2)
|
12
|
+
actionpack (= 6.0.2.2)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
actionpack (=
|
17
|
-
|
18
|
-
|
15
|
+
actionmailbox (6.0.2.2)
|
16
|
+
actionpack (= 6.0.2.2)
|
17
|
+
activejob (= 6.0.2.2)
|
18
|
+
activerecord (= 6.0.2.2)
|
19
|
+
activestorage (= 6.0.2.2)
|
20
|
+
activesupport (= 6.0.2.2)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.0.2.2)
|
23
|
+
actionpack (= 6.0.2.2)
|
24
|
+
actionview (= 6.0.2.2)
|
25
|
+
activejob (= 6.0.2.2)
|
19
26
|
mail (~> 2.5, >= 2.5.4)
|
20
27
|
rails-dom-testing (~> 2.0)
|
21
|
-
actionpack (
|
22
|
-
actionview (=
|
23
|
-
activesupport (=
|
24
|
-
rack (~> 2.0)
|
28
|
+
actionpack (6.0.2.2)
|
29
|
+
actionview (= 6.0.2.2)
|
30
|
+
activesupport (= 6.0.2.2)
|
31
|
+
rack (~> 2.0, >= 2.0.8)
|
25
32
|
rack-test (>= 0.6.3)
|
26
33
|
rails-dom-testing (~> 2.0)
|
27
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
28
|
-
|
29
|
-
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
+
actiontext (6.0.2.2)
|
36
|
+
actionpack (= 6.0.2.2)
|
37
|
+
activerecord (= 6.0.2.2)
|
38
|
+
activestorage (= 6.0.2.2)
|
39
|
+
activesupport (= 6.0.2.2)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
actionview (6.0.2.2)
|
42
|
+
activesupport (= 6.0.2.2)
|
30
43
|
builder (~> 3.1)
|
31
44
|
erubi (~> 1.4)
|
32
45
|
rails-dom-testing (~> 2.0)
|
33
|
-
rails-html-sanitizer (~> 1.
|
34
|
-
activejob (
|
35
|
-
activesupport (=
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
+
activejob (6.0.2.2)
|
48
|
+
activesupport (= 6.0.2.2)
|
36
49
|
globalid (>= 0.3.6)
|
37
|
-
activemodel (
|
38
|
-
activesupport (=
|
39
|
-
activerecord (
|
40
|
-
activemodel (=
|
41
|
-
activesupport (=
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
activerecord (=
|
50
|
+
activemodel (6.0.2.2)
|
51
|
+
activesupport (= 6.0.2.2)
|
52
|
+
activerecord (6.0.2.2)
|
53
|
+
activemodel (= 6.0.2.2)
|
54
|
+
activesupport (= 6.0.2.2)
|
55
|
+
activestorage (6.0.2.2)
|
56
|
+
actionpack (= 6.0.2.2)
|
57
|
+
activejob (= 6.0.2.2)
|
58
|
+
activerecord (= 6.0.2.2)
|
46
59
|
marcel (~> 0.3.1)
|
47
|
-
activesupport (
|
60
|
+
activesupport (6.0.2.2)
|
48
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
62
|
i18n (>= 0.7, < 2)
|
50
63
|
minitest (~> 5.1)
|
51
64
|
tzinfo (~> 1.1)
|
52
|
-
|
53
|
-
builder (3.2.
|
54
|
-
concurrent-ruby (1.1.
|
55
|
-
crass (1.0.
|
65
|
+
zeitwerk (~> 2.2)
|
66
|
+
builder (3.2.4)
|
67
|
+
concurrent-ruby (1.1.6)
|
68
|
+
crass (1.0.6)
|
56
69
|
diff-lcs (1.3)
|
57
|
-
erubi (1.
|
70
|
+
erubi (1.9.0)
|
58
71
|
globalid (0.4.2)
|
59
72
|
activesupport (>= 4.2.0)
|
60
|
-
i18n (1.
|
73
|
+
i18n (1.8.2)
|
61
74
|
concurrent-ruby (~> 1.0)
|
62
|
-
kaminari (1.
|
75
|
+
kaminari (1.2.0)
|
63
76
|
activesupport (>= 4.1.0)
|
64
|
-
kaminari-actionview (= 1.
|
65
|
-
kaminari-activerecord (= 1.
|
66
|
-
kaminari-core (= 1.
|
67
|
-
kaminari-actionview (1.
|
77
|
+
kaminari-actionview (= 1.2.0)
|
78
|
+
kaminari-activerecord (= 1.2.0)
|
79
|
+
kaminari-core (= 1.2.0)
|
80
|
+
kaminari-actionview (1.2.0)
|
68
81
|
actionview
|
69
|
-
kaminari-core (= 1.
|
70
|
-
kaminari-activerecord (1.
|
82
|
+
kaminari-core (= 1.2.0)
|
83
|
+
kaminari-activerecord (1.2.0)
|
71
84
|
activerecord
|
72
|
-
kaminari-core (= 1.
|
73
|
-
kaminari-core (1.
|
74
|
-
loofah (2.
|
85
|
+
kaminari-core (= 1.2.0)
|
86
|
+
kaminari-core (1.2.0)
|
87
|
+
loofah (2.4.0)
|
75
88
|
crass (~> 1.0.2)
|
76
89
|
nokogiri (>= 1.5.9)
|
77
90
|
mail (2.7.1)
|
78
91
|
mini_mime (>= 0.1.1)
|
79
92
|
marcel (0.3.3)
|
80
93
|
mimemagic (~> 0.3.2)
|
81
|
-
method_source (0.
|
82
|
-
mimemagic (0.3.
|
83
|
-
mini_mime (1.0.
|
94
|
+
method_source (1.0.0)
|
95
|
+
mimemagic (0.3.4)
|
96
|
+
mini_mime (1.0.2)
|
84
97
|
mini_portile2 (2.4.0)
|
85
|
-
minitest (5.
|
86
|
-
nio4r (2.
|
87
|
-
nokogiri (1.10.
|
98
|
+
minitest (5.14.0)
|
99
|
+
nio4r (2.5.2)
|
100
|
+
nokogiri (1.10.9)
|
88
101
|
mini_portile2 (~> 2.4.0)
|
89
|
-
rack (2.
|
102
|
+
rack (2.2.2)
|
90
103
|
rack-test (1.1.0)
|
91
104
|
rack (>= 1.0, < 3)
|
92
|
-
rails (
|
93
|
-
actioncable (=
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
105
|
+
rails (6.0.2.2)
|
106
|
+
actioncable (= 6.0.2.2)
|
107
|
+
actionmailbox (= 6.0.2.2)
|
108
|
+
actionmailer (= 6.0.2.2)
|
109
|
+
actionpack (= 6.0.2.2)
|
110
|
+
actiontext (= 6.0.2.2)
|
111
|
+
actionview (= 6.0.2.2)
|
112
|
+
activejob (= 6.0.2.2)
|
113
|
+
activemodel (= 6.0.2.2)
|
114
|
+
activerecord (= 6.0.2.2)
|
115
|
+
activestorage (= 6.0.2.2)
|
116
|
+
activesupport (= 6.0.2.2)
|
102
117
|
bundler (>= 1.3.0)
|
103
|
-
railties (=
|
118
|
+
railties (= 6.0.2.2)
|
104
119
|
sprockets-rails (>= 2.0.0)
|
105
120
|
rails-dom-testing (2.0.3)
|
106
121
|
activesupport (>= 4.2.0)
|
107
122
|
nokogiri (>= 1.6)
|
108
|
-
rails-html-sanitizer (1.0
|
109
|
-
loofah (~> 2.
|
110
|
-
railties (
|
111
|
-
actionpack (=
|
112
|
-
activesupport (=
|
123
|
+
rails-html-sanitizer (1.3.0)
|
124
|
+
loofah (~> 2.3)
|
125
|
+
railties (6.0.2.2)
|
126
|
+
actionpack (= 6.0.2.2)
|
127
|
+
activesupport (= 6.0.2.2)
|
113
128
|
method_source
|
114
129
|
rake (>= 0.8.7)
|
115
|
-
thor (>= 0.
|
116
|
-
rake (
|
130
|
+
thor (>= 0.20.3, < 2.0)
|
131
|
+
rake (13.0.1)
|
117
132
|
rspec (3.8.0)
|
118
133
|
rspec-core (~> 3.8.0)
|
119
134
|
rspec-expectations (~> 3.8.0)
|
@@ -127,20 +142,21 @@ GEM
|
|
127
142
|
diff-lcs (>= 1.2.0, < 2.0)
|
128
143
|
rspec-support (~> 3.8.0)
|
129
144
|
rspec-support (3.8.0)
|
130
|
-
sprockets (
|
145
|
+
sprockets (4.0.0)
|
131
146
|
concurrent-ruby (~> 1.0)
|
132
147
|
rack (> 1, < 3)
|
133
148
|
sprockets-rails (3.2.1)
|
134
149
|
actionpack (>= 4.0)
|
135
150
|
activesupport (>= 4.0)
|
136
151
|
sprockets (>= 3.0.0)
|
137
|
-
thor (0.
|
152
|
+
thor (1.0.1)
|
138
153
|
thread_safe (0.3.6)
|
139
|
-
tzinfo (1.2.
|
154
|
+
tzinfo (1.2.6)
|
140
155
|
thread_safe (~> 0.1)
|
141
|
-
websocket-driver (0.7.
|
156
|
+
websocket-driver (0.7.1)
|
142
157
|
websocket-extensions (>= 0.1.0)
|
143
|
-
websocket-extensions (0.1.
|
158
|
+
websocket-extensions (0.1.4)
|
159
|
+
zeitwerk (2.3.0)
|
144
160
|
|
145
161
|
PLATFORMS
|
146
162
|
ruby
|
@@ -148,7 +164,7 @@ PLATFORMS
|
|
148
164
|
DEPENDENCIES
|
149
165
|
bundler (~> 2.0)
|
150
166
|
jsonapi_actions!
|
151
|
-
rake (~>
|
167
|
+
rake (~> 13.0)
|
152
168
|
rspec (~> 3.0)
|
153
169
|
|
154
170
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# JsonapiActions
|
2
2
|
|
3
3
|
Instantly create flexible API controllers that are compatible with [JSON:API](https://jsonapi.org/).
|
4
|
-
Utilize your existing [
|
4
|
+
Utilize your existing [JSONAPI::Serializer](https://github.com/jsonapi-serializer/jsonapi-serializer),
|
5
|
+
[FastJsonapi](https://github.com/Netflix/fast_jsonapi), or
|
5
6
|
[ActiveModel::Serializer](https://github.com/rails-api/active_model_serializers) serialization library, or bring your
|
6
7
|
own. Scope and authenticate with optional [Pundit](https://github.com/varvet/pundit) policies and/or Controller specific
|
7
8
|
methods.
|
@@ -24,8 +25,7 @@ $ bundle install
|
|
24
25
|
|
25
26
|
### Basic Setup
|
26
27
|
|
27
|
-
Include
|
28
|
-
your base controller.
|
28
|
+
Include `JsonapiActions` in your base controller.
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
# app/controllers/api/v1/base_controller.rb
|
@@ -60,7 +60,6 @@ Rails.application.routes.draw do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
63
|
```
|
65
64
|
|
66
65
|
### parent_scope
|
@@ -140,7 +139,7 @@ end
|
|
140
139
|
```
|
141
140
|
|
142
141
|
### #json_response
|
143
|
-
Response data is formatted so that it can be rendered with `FastJsonapi
|
142
|
+
Response data is formatted so that it can be rendered with `JSONAPI::Serializer`, `FastJsonapi`, or `ActiveModel::Serializer`.
|
144
143
|
If you are using a different serializer, or would like to further change the response. Then you will need to override
|
145
144
|
`#response`, which defines the arguments for `render`.
|
146
145
|
|
@@ -163,7 +162,7 @@ end
|
|
163
162
|
|
164
163
|
## Pundit
|
165
164
|
|
166
|
-
JsonapiActions
|
165
|
+
JsonapiActions is built to use Pundit for authorization. We utilize action authorization, policy scope,
|
167
166
|
and permitted params.
|
168
167
|
|
169
168
|
```ruby
|
data/jsonapi_actions.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Kevin Pheasey"]
|
10
10
|
spec.email = ["kevin@kpsoftware.io"]
|
11
11
|
|
12
|
-
spec.summary = "Rails
|
13
|
-
spec.description = "Implement Rails
|
12
|
+
spec.summary = "Rails JSON:API Controller Actions"
|
13
|
+
spec.description = "Implement Rails JSON:API compliant controller actions."
|
14
14
|
spec.homepage = "https://github.com/kp-software/jsonapi_actions"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
|
30
|
-
spec.add_dependency 'rails', '>= 4.0', '<
|
30
|
+
spec.add_dependency 'rails', '>= 4.0', '< 7.0'
|
31
31
|
spec.add_dependency 'kaminari', '>= 1.0', '< 2.0'
|
32
32
|
end
|
data/lib/jsonapi_actions.rb
CHANGED
@@ -120,11 +120,11 @@ module JsonapiActions
|
|
120
120
|
|
121
121
|
def page
|
122
122
|
@page ||= begin
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
123
|
+
page = {}
|
124
|
+
page[:number] = (params.dig(:page, :number) || 1).to_i
|
125
|
+
page[:size] = [[(params.dig(:page, :size) || 20).to_i, 1000].min, 1].max
|
126
|
+
page
|
127
|
+
end
|
128
128
|
end
|
129
129
|
|
130
130
|
def set_record
|
@@ -174,7 +174,7 @@ module JsonapiActions
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def json_response(data, options = {})
|
177
|
-
if
|
177
|
+
if defined?(JSONAPI::Serializer) || defined?(FastJsonapi)
|
178
178
|
{
|
179
179
|
json: serializer(data).new(data, options.deep_merge(
|
180
180
|
include: include_param,
|
@@ -185,7 +185,7 @@ module JsonapiActions
|
|
185
185
|
)
|
186
186
|
}
|
187
187
|
|
188
|
-
elsif
|
188
|
+
elsif defined?(ActiveModel::Serializer)
|
189
189
|
{ json: data }.merge(meta: metadata, include: include_param).merge(options)
|
190
190
|
|
191
191
|
else
|
@@ -194,10 +194,21 @@ module JsonapiActions
|
|
194
194
|
end
|
195
195
|
|
196
196
|
def serializer(data = nil)
|
197
|
-
|
198
|
-
|
199
|
-
data.try(:
|
200
|
-
"#{
|
197
|
+
serializer_classes = [
|
198
|
+
self.class.serializer,
|
199
|
+
data.try(:serializer_class),
|
200
|
+
"#{data.class.name}Serializer".safe_constantize,
|
201
|
+
data.try(:first).try(:serializer_class),
|
202
|
+
"#{data.try(:first).class.name}Serializer".safe_constantize
|
203
|
+
].compact
|
204
|
+
|
205
|
+
if serializer_classes.any?
|
206
|
+
serializer_classes.first
|
207
|
+
else
|
208
|
+
"#{model.name}Serializer".safe_constantize
|
209
|
+
end
|
210
|
+
rescue NoMethodError, NameError
|
211
|
+
raise 'Unknown serializer'
|
201
212
|
end
|
202
213
|
|
203
214
|
def eager_load(records)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_actions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pheasey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
version: '4.0'
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '7.0'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
version: '4.0'
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '7.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: kaminari
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- - "<"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '2.0'
|
95
|
-
description: Implement Rails
|
95
|
+
description: Implement Rails JSON:API compliant controller actions.
|
96
96
|
email:
|
97
97
|
- kevin@kpsoftware.io
|
98
98
|
executables: []
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".rspec"
|
105
105
|
- ".ruby-gemset"
|
106
106
|
- ".ruby-version"
|
107
|
+
- CHANGELOG.md
|
107
108
|
- CODE_OF_CONDUCT.md
|
108
109
|
- Gemfile
|
109
110
|
- Gemfile.lock
|
@@ -123,7 +124,7 @@ homepage: https://github.com/kp-software/jsonapi_actions
|
|
123
124
|
licenses:
|
124
125
|
- MIT
|
125
126
|
metadata: {}
|
126
|
-
post_install_message:
|
127
|
+
post_install_message:
|
127
128
|
rdoc_options: []
|
128
129
|
require_paths:
|
129
130
|
- lib
|
@@ -138,9 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
|
142
|
-
|
143
|
-
signing_key:
|
142
|
+
rubygems_version: 3.0.8
|
143
|
+
signing_key:
|
144
144
|
specification_version: 4
|
145
|
-
summary: Rails
|
145
|
+
summary: Rails JSON:API Controller Actions
|
146
146
|
test_files: []
|