api-blocks 0.4.6 → 0.4.7

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: 350e8ea9a460e3a5d7306c60bf497aa5a03b173414c038c0595cd4ffd0bad210
4
- data.tar.gz: 422dfc7fd2cecbf43961a501788aaa4e297a0de4929879aeb6c4ab841c4a8cc3
3
+ metadata.gz: 4a8c93e0ece56eb8dac64f1584d4b352e6943f8abe3609e57c3a8dab48041dad
4
+ data.tar.gz: 7787836a06bbd32a4c5b32aa431c7f41e26b40f27064e7255930e40620023bf5
5
5
  SHA512:
6
- metadata.gz: 157d73d50b4d51ef1a6849abd390c8d102c9065c0a9824732d7dbd2c7d591f6a94419f6c7ef65d890e27d8f1544aa012eab7995ab87fa610020a192517957661
7
- data.tar.gz: 344687ec6e19b861234215d2d911bbf8c464771d9b86dbf0b05ab73da154063bbdf6b9e666cd2a1cd22cbf56cf67e008cf1afa47bcbbb1b12e6ff2af6efbb905
6
+ metadata.gz: ea3b30b3e1b852574678df868c61dd01ab03cd81145930891ff2267fe209ea189f4653fd331bf29e88faec341d311213b53d960bd254cd88f4aae3a3f99e4aaa
7
+ data.tar.gz: f22b8967bb0aec216e68c9a474164f82c7aa7a5a3472b413e9db4d5ba6025ac22e0059f8276840495ebc4ee6c22457a9ecf86996906e201e89e824963f83c2ec
@@ -96,7 +96,7 @@ module ApiBlocks::Doorkeeper::Invitations::Controller
96
96
 
97
97
  # Returns the user model class.
98
98
  def user_model
99
- raise 'the method `user_model` must be implemented on your password controller' # rubocop:disable Metrics/LineLength
99
+ raise 'the method `user_model` must be implemented on your invitations controller' # rubocop:disable Metrics/LineLength
100
100
  end
101
101
  end
102
102
  end
@@ -3,6 +3,7 @@
3
3
  require 'action_controller/responder'
4
4
  require 'responders'
5
5
  require 'dry/monads/result'
6
+ require 'dry/validation/result'
6
7
 
7
8
  # ApiBlocks::Responder provides a responder with better error handling and
8
9
  # `ApiBlocks::Interactor` through `Dry::Monads::Result` support.
@@ -14,15 +15,17 @@ class ApiBlocks::Responder < ActionController::Responder
14
15
  # code.
15
16
  #
16
17
  def resource_errors
17
- case @resource
18
- when ApplicationRecord
19
- [{ errors: @resource.errors }, :unprocessable_entity]
18
+ case resource
19
+ when Dry::Validation::Result
20
+ [{ errors: resource.errors.to_h }, :unprocessable_entity]
20
21
  when ActiveRecord::RecordInvalid
21
- [{ errors: @resource.record.errors }, :unprocessable_entity]
22
- else
22
+ [{ errors: resource.record.errors }, :unprocessable_entity]
23
+ when StandardError
23
24
  # propagate the error so it can be handled through the standard rails
24
25
  # error handlers.
25
- raise @resource
26
+ raise resource
27
+ else
28
+ super
26
29
  end
27
30
  end
28
31
 
@@ -45,13 +48,8 @@ class ApiBlocks::Responder < ActionController::Responder
45
48
  # assign the failure instead.
46
49
  #
47
50
  def to_format
48
- return super unless resource.is_a?(Dry::Monads::Result)
49
-
50
- # unwrap the result monad so it can be processed by
51
- # ActionController::Responder
52
- resource.fmap { |result| @resource = result }.or do |failure|
53
- @resource = failure
54
- @failure = true
51
+ if resource.is_a?(Dry::Monads::Result)
52
+ unwrap_dry_result
55
53
  end
56
54
 
57
55
  super
@@ -63,6 +61,10 @@ class ApiBlocks::Responder < ActionController::Responder
63
61
  super
64
62
  end
65
63
 
64
+ def json_resource_errors
65
+ [{ errors: resource.errors }, :unprocessable_entity]
66
+ end
67
+
66
68
  # Override ActionController::Responder#api_behavior in order to
67
69
  # provide one that matches our API documentation.
68
70
  #
@@ -80,4 +82,15 @@ class ApiBlocks::Responder < ActionController::Responder
80
82
  head :no_content
81
83
  end
82
84
  end
85
+
86
+ private
87
+
88
+ def unwrap_dry_result
89
+ # unwrap the result monad so it can be processed by
90
+ # ActionController::Responder
91
+ resource.fmap { |result| @resource = result }.or do |failure|
92
+ @resource = failure
93
+ @failure = true
94
+ end
95
+ end
83
96
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ApiBlocks
4
4
  # Current version of ApiBlocks
5
- VERSION = '0.4.6'
5
+ VERSION = '0.4.7'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul d'Hubert