api-blocks 0.4.6 → 0.4.7
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/lib/api_blocks/doorkeeper/invitations/controller.rb +1 -1
- data/lib/api_blocks/responder.rb +26 -13
- data/lib/api_blocks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a8c93e0ece56eb8dac64f1584d4b352e6943f8abe3609e57c3a8dab48041dad
|
4
|
+
data.tar.gz: 7787836a06bbd32a4c5b32aa431c7f41e26b40f27064e7255930e40620023bf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/api_blocks/responder.rb
CHANGED
@@ -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
|
18
|
-
when
|
19
|
-
[{ errors:
|
18
|
+
case resource
|
19
|
+
when Dry::Validation::Result
|
20
|
+
[{ errors: resource.errors.to_h }, :unprocessable_entity]
|
20
21
|
when ActiveRecord::RecordInvalid
|
21
|
-
[{ errors:
|
22
|
-
|
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
|
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
|
-
|
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
|
data/lib/api_blocks/version.rb
CHANGED