api-blocks 0.7.0 → 0.8.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.
@@ -1,22 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "problem_details-rails"
3
+ require 'problem_details-rails'
4
4
 
5
5
  # ApiBlocks::Railtie implements the Rails integration for ApiBlocks.
6
6
  #
7
7
  # @private
8
8
  #
9
- class ApiBlocks::Railtie < Rails::Railtie
10
- generators do
11
- require_relative 'doorkeeper/passwords/migration_generator'
12
- require_relative 'doorkeeper/invitations/migration_generator'
13
- end
9
+ module ApiBlocks
10
+ class Railtie < Rails::Railtie
11
+ generators do
12
+ require_relative 'doorkeeper/passwords/migration_generator'
13
+ require_relative 'doorkeeper/invitations/migration_generator'
14
+ end
14
15
 
15
- initializer "blueprinter.batch_loader_integration" do |app|
16
- app.config.after_initialize do
17
- next unless ApiBlocks.config.blueprinter.use_batch_loader
16
+ initializer 'blueprinter.batch_loader_integration' do |app|
17
+ app.config.after_initialize do
18
+ next unless ApiBlocks.config.blueprinter.use_batch_loader
18
19
 
19
- require_relative "blueprinter/association_extractor"
20
+ require_relative 'blueprinter/association_extractor'
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,102 +1,102 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "action_controller/responder"
4
- require "responders"
5
- require "dry/monads/result"
6
- require "dry/validation/result"
3
+ require 'action_controller/responder'
4
+ require 'responders'
5
+ require 'dry/monads/result'
6
+ require 'dry/validation/result'
7
7
 
8
8
  # ApiBlocks::Responder provides a responder with better error handling and
9
9
  # `ApiBlocks::Interactor` through `Dry::Monads::Result` support.
10
10
  #
11
- class ApiBlocks::Responder < ActionController::Responder
12
- include Responders::HttpCacheResponder
11
+ module ApiBlocks
12
+ class Responder < ActionController::Responder
13
+ include Responders::HttpCacheResponder
13
14
 
14
- # Override resource_errors to handle more error kinds and return a status
15
- # code.
16
- #
17
- def resource_errors
18
- case resource
19
- when Dry::Validation::Result
20
- [{ errors: resource.errors.to_h }, :unprocessable_entity]
21
- when ActiveRecord::RecordInvalid
22
- [{ errors: resource.record.errors }, :unprocessable_entity]
23
- when ActiveModel::ValidationError
24
- [{ errors: resource.model.errors }, :unprocessable_entity]
25
- when String
26
- [{ detail: resource }, :internal_server_error]
27
- when ProblemDetails::Document
28
- [resource.to_h, resource.status]
29
- when StandardError
30
- # propagate the error so it can be handled through the standard rails
31
- # error handlers.
32
- raise resource
33
- else
34
- super
15
+ # Override resource_errors to handle more error kinds and return a status
16
+ # code.
17
+ #
18
+ def resource_errors
19
+ case resource
20
+ when Dry::Validation::Result
21
+ [{ errors: resource.errors.to_h }, :unprocessable_entity]
22
+ when ActiveRecord::RecordInvalid
23
+ [{ errors: resource.record.errors }, :unprocessable_entity]
24
+ when ActiveModel::ValidationError
25
+ [{ errors: resource.model.errors }, :unprocessable_entity]
26
+ when String
27
+ [{ detail: resource }, :internal_server_error]
28
+ when ProblemDetails::Document
29
+ [resource.to_h, resource.status]
30
+ when StandardError
31
+ # propagate the error so it can be handled through the standard rails
32
+ # error handlers.
33
+ raise resource
34
+ else
35
+ super
36
+ end
35
37
  end
36
- end
37
38
 
38
- # Display is just a shortcut to render a resource's errors with the current
39
- # format using `problem_details` when format is set to JSON.
40
- #
41
- def display_errors
42
- return super unless format == :json
39
+ # Display is just a shortcut to render a resource's errors with the current
40
+ # format using `problem_details` when format is set to JSON.
41
+ #
42
+ def display_errors
43
+ return super unless format == :json
43
44
 
44
- errors, status = resource_errors
45
-
46
- controller.render problem: errors, status: status
47
- end
45
+ errors, status = resource_errors
48
46
 
49
- # All other formats follow the procedure below. First we try to render a
50
- # template, if the template is not available, we verify if the resource
51
- # responds to :to_format and display it.
52
- #
53
- # In addition, if the resource is a Dry::Monads::Result we unwrap it and
54
- # assign the failure instead.
55
- #
56
- def to_format
57
- if resource.is_a?(Dry::Monads::Result)
58
- unwrap_dry_result
47
+ controller.render problem: errors, status: status
59
48
  end
60
49
 
61
- super
62
- end
50
+ # All other formats follow the procedure below. First we try to render a
51
+ # template, if the template is not available, we verify if the resource
52
+ # responds to :to_format and display it.
53
+ #
54
+ # In addition, if the resource is a Dry::Monads::Result we unwrap it and
55
+ # assign the failure instead.
56
+ #
57
+ def to_format
58
+ unwrap_dry_result if resource.is_a?(Dry::Monads::Result)
59
+
60
+ super
61
+ end
63
62
 
64
- def has_errors? # rubocop:disable Naming/PredicateName
65
- return true if @failure
63
+ def has_errors? # rubocop:disable Naming/PredicateName
64
+ return true if @failure
66
65
 
67
- super
68
- end
66
+ super
67
+ end
69
68
 
70
- def json_resource_errors
71
- [{ errors: resource.errors }, :unprocessable_entity]
72
- end
69
+ def json_resource_errors
70
+ [{ errors: resource.errors }, :unprocessable_entity]
71
+ end
73
72
 
74
- # Override ActionController::Responder#api_behavior in order to
75
- # provide one that matches our API documentation.
76
- #
77
- # The only difference so far is that on POST we do not render `status:
78
- # :created` along with a `Location` header.
79
- #
80
- # Moreover, we display the resource on PUT.
81
- #
82
- def api_behavior
83
- raise(MissingRenderer, format) unless has_renderer?
73
+ # Override ActionController::Responder#api_behavior in order to
74
+ # provide one that matches our API documentation.
75
+ #
76
+ # The only difference so far is that on POST we do not render `status:
77
+ # :created` along with a `Location` header.
78
+ #
79
+ # Moreover, we display the resource on PUT.
80
+ #
81
+ def api_behavior
82
+ raise(MissingRenderer, format) unless has_renderer?
84
83
 
85
- if get? || post? || put?
86
- display resource
87
- else
88
- head :no_content
84
+ if get? || post? || put?
85
+ display resource
86
+ else
87
+ head :no_content
88
+ end
89
89
  end
90
- end
91
90
 
92
- private
91
+ private
93
92
 
94
- def unwrap_dry_result
95
- # unwrap the result monad so it can be processed by
96
- # ActionController::Responder
97
- resource.fmap { |result| @resource = result }.or do |failure|
98
- @resource = failure
99
- @failure = true
93
+ def unwrap_dry_result
94
+ # unwrap the result monad so it can be processed by
95
+ # ActionController::Responder
96
+ resource.fmap { |result| @resource = result }.or do |failure|
97
+ @resource = failure
98
+ @failure = true
99
+ end
100
100
  end
101
101
  end
102
102
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ApiBlocks
4
4
  # Current version of ApiBlocks
5
- VERSION = "0.7.0"
5
+ VERSION = '0.8.0'
6
6
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul d'Hubert
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-10-29 00:00:00.000000000 Z
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 5.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: dry-monads
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +136,6 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: 3.0.0
125
- - !ruby/object:Gem::Dependency
126
- name: dry-configurable
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.8'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.8'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: bundler
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - '='
228
228
  - !ruby/object:Gem::Version
229
- version: 0.82.0
229
+ version: 1.6.1
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - '='
235
235
  - !ruby/object:Gem::Version
236
- version: 0.82.0
236
+ version: 1.6.1
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: yard
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -271,6 +271,7 @@ files:
271
271
  - lib/api-blocks.rb
272
272
  - lib/api_blocks.rb
273
273
  - lib/api_blocks/blueprinter/association_extractor.rb
274
+ - lib/api_blocks/blueprinter/join_keys.rb
274
275
  - lib/api_blocks/controller.rb
275
276
  - lib/api_blocks/doorkeeper.rb
276
277
  - lib/api_blocks/doorkeeper/invitations.rb
@@ -290,7 +291,7 @@ homepage: https://github.com/tymate/api-blocks
290
291
  licenses:
291
292
  - MIT
292
293
  metadata: {}
293
- post_install_message:
294
+ post_install_message:
294
295
  rdoc_options: []
295
296
  require_paths:
296
297
  - lib
@@ -305,8 +306,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
306
  - !ruby/object:Gem::Version
306
307
  version: '0'
307
308
  requirements: []
308
- rubygems_version: 3.0.6
309
- signing_key:
309
+ rubygems_version: 3.1.3
310
+ signing_key:
310
311
  specification_version: 4
311
312
  summary: Simple and consistent rails api extensions
312
313
  test_files: []