jsonapi_actions 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7715c24debc264384b44d0d58e7c35bb233933a5d7ce65dac9cf1d5b7442a20
4
- data.tar.gz: d4280a01b00fa35db370ffa051a6bdab451400d3a4517097e0901ddf2237dbc5
3
+ metadata.gz: dd75b7ea62934cf27cc351d4327cf302af2ab1f5aed66d6d6075575e974d90b6
4
+ data.tar.gz: 56008596f5f59e8eb0640b2d0be4b81eed49dd6fdc7e0f08af5d9f10fc683687
5
5
  SHA512:
6
- metadata.gz: 1b3ede4f07f319d0fbef81a168ce9d98c84e81a2685df7ea826c347f85ae6502e4a45a275e8e5886e539aeab8c12fad19090f9a7db163242383214772b2e2338
7
- data.tar.gz: 3a3e17111e6759c9c79494873b61a4da4993e7d0c59cd03419368ebd6bf8a385c3b136068b5da4692d9d5917ff9eb74bdb4b3e0e541892508ad94d10bc66e664
6
+ metadata.gz: 709f2ae770a5efbfca5252997c866205a898eb85cc77dddc5517a936d99910e169f7767ecd1a677ec33b4aef30157236528260e9d629cb937578250fb489350b
7
+ data.tar.gz: 47e353f3fa687d0ee7a8463dfa412b110982bfcf10c2f294084603bce6f12d29ae937befb795549be5b3bc36f59ce2c9a2f85c4368a2c0a217a57c79159f93c5
@@ -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
@@ -1,119 +1,134 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jsonapi_actions (0.1.0)
4
+ jsonapi_actions (0.1.2)
5
5
  kaminari (>= 1.0, < 2.0)
6
- rails (>= 4.0, < 6.0)
6
+ rails (>= 4.0, < 7.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (5.2.2)
12
- actionpack (= 5.2.2)
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
- actionmailer (5.2.2)
16
- actionpack (= 5.2.2)
17
- actionview (= 5.2.2)
18
- activejob (= 5.2.2)
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 (5.2.2)
22
- actionview (= 5.2.2)
23
- activesupport (= 5.2.2)
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.2)
28
- actionview (5.2.2)
29
- activesupport (= 5.2.2)
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.0, >= 1.0.3)
34
- activejob (5.2.2)
35
- activesupport (= 5.2.2)
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 (5.2.2)
38
- activesupport (= 5.2.2)
39
- activerecord (5.2.2)
40
- activemodel (= 5.2.2)
41
- activesupport (= 5.2.2)
42
- arel (>= 9.0)
43
- activestorage (5.2.2)
44
- actionpack (= 5.2.2)
45
- activerecord (= 5.2.2)
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 (5.2.2)
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
- arel (9.0.0)
53
- builder (3.2.3)
54
- concurrent-ruby (1.1.5)
55
- crass (1.0.4)
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.8.0)
70
+ erubi (1.9.0)
58
71
  globalid (0.4.2)
59
72
  activesupport (>= 4.2.0)
60
- i18n (1.6.0)
73
+ i18n (1.8.2)
61
74
  concurrent-ruby (~> 1.0)
62
- kaminari (1.1.1)
75
+ kaminari (1.2.0)
63
76
  activesupport (>= 4.1.0)
64
- kaminari-actionview (= 1.1.1)
65
- kaminari-activerecord (= 1.1.1)
66
- kaminari-core (= 1.1.1)
67
- kaminari-actionview (1.1.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.1.1)
70
- kaminari-activerecord (1.1.1)
82
+ kaminari-core (= 1.2.0)
83
+ kaminari-activerecord (1.2.0)
71
84
  activerecord
72
- kaminari-core (= 1.1.1)
73
- kaminari-core (1.1.1)
74
- loofah (2.2.3)
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.9.2)
82
- mimemagic (0.3.3)
83
- mini_mime (1.0.1)
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.11.3)
86
- nio4r (2.3.1)
87
- nokogiri (1.10.1)
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.0.6)
102
+ rack (2.2.2)
90
103
  rack-test (1.1.0)
91
104
  rack (>= 1.0, < 3)
92
- rails (5.2.2)
93
- actioncable (= 5.2.2)
94
- actionmailer (= 5.2.2)
95
- actionpack (= 5.2.2)
96
- actionview (= 5.2.2)
97
- activejob (= 5.2.2)
98
- activemodel (= 5.2.2)
99
- activerecord (= 5.2.2)
100
- activestorage (= 5.2.2)
101
- activesupport (= 5.2.2)
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 (= 5.2.2)
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.4)
109
- loofah (~> 2.2, >= 2.2.2)
110
- railties (5.2.2)
111
- actionpack (= 5.2.2)
112
- activesupport (= 5.2.2)
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.19.0, < 2.0)
116
- rake (10.5.0)
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 (3.7.2)
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.20.3)
152
+ thor (1.0.1)
138
153
  thread_safe (0.3.6)
139
- tzinfo (1.2.5)
154
+ tzinfo (1.2.6)
140
155
  thread_safe (~> 0.1)
141
- websocket-driver (0.7.0)
156
+ websocket-driver (0.7.1)
142
157
  websocket-extensions (>= 0.1.0)
143
- websocket-extensions (0.1.3)
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 (~> 10.0)
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 [FastJsonapi](https://github.com/Netflix/fast_jsonapi) or
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 the `JsonapiActions::ErrorHandling` and `JsonapiActions::ErrorHandling` modules in
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` or `ActiveModel::Serializer`.
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 are built to use Pundit for authorization. We utilize action authorization, policy scope,
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
@@ -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 JSONAPI Controller Actions"
13
- spec.description = "Implement Rails JSONAPI compliant controller actions."
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", "~> 10.0"
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', '< 6.0'
30
+ spec.add_dependency 'rails', '>= 4.0', '< 7.0'
31
31
  spec.add_dependency 'kaminari', '>= 1.0', '< 2.0'
32
32
  end
@@ -120,11 +120,11 @@ module JsonapiActions
120
120
 
121
121
  def page
122
122
  @page ||= begin
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
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 Gem::Specification.find_by_name('fast_jsonapi')
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 Gem::Specification.find_by_name('active_model_serializers')
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
- self.class.serializer ||
198
- data.try(:serializer_class) ||
199
- data.try(:first).try(:serializer_class) ||
200
- "#{model.name}Serializer".constantize
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)
@@ -1,3 +1,3 @@
1
1
  module JsonapiActions
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.1.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: 2019-09-17 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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: '6.0'
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: '6.0'
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 JSONAPI compliant controller actions.
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
- rubyforge_project:
142
- rubygems_version: 2.7.8
143
- signing_key:
142
+ rubygems_version: 3.0.8
143
+ signing_key:
144
144
  specification_version: 4
145
- summary: Rails JSONAPI Controller Actions
145
+ summary: Rails JSON:API Controller Actions
146
146
  test_files: []