the_help 3.0.0 → 3.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -0
- data/lib/the_help/service.rb +10 -2
- data/lib/the_help/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: 7c3bac0cd5079035a765ff1018c38020e8f7805b00fd0e7123da0a9fe2547e15
|
4
|
+
data.tar.gz: 7708a7c8c5523525b6ee909bd1395b03b898f69bb4fdab7e91b14fe6817e332c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2a35d48df57043c329f3425539ca6e8aa181bd2f9b420977c5d871caab068d1a100ad8ae2d9b924dd56022340e0c0f4c5cb4587e510955627b9db428a4c2a9b
|
7
|
+
data.tar.gz: b91c4d0a6601a062987b77fbdb53760959b20332d8a071b216087568b1934ef99d5cd7e72dc19ecda5074c468e6d601154386a85f8c1e711aa69772b75e4433c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -118,6 +118,33 @@ call_service(MyService, foo: false)
|
|
118
118
|
# raises the exception ArgumentError with the message 'foo must be true'
|
119
119
|
```
|
120
120
|
|
121
|
+
If you want to make sure the exception's backtrace points to the correct line of code, raise the
|
122
|
+
exception in a block provided to the `#error` method:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
class MyService < TheHelp::Service
|
126
|
+
authorization_policy allow_all: true
|
127
|
+
|
128
|
+
input :foo
|
129
|
+
|
130
|
+
main do
|
131
|
+
if foo
|
132
|
+
result.success 'bar'
|
133
|
+
else
|
134
|
+
result.error { raise ArgumentError.new('foo must be true') }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
call_service(MyService, foo: false)
|
140
|
+
# raises the exception ArgumentError with the message 'foo must be true'
|
141
|
+
```
|
142
|
+
|
143
|
+
With the block form, the backtrace will point to the line where the exception was first raised
|
144
|
+
rather than to the `#value!` method, however all other code execution will continue until the
|
145
|
+
point where the `#value!` method is called (as long as the exception is a subtype of
|
146
|
+
`StandardError`.)
|
147
|
+
|
121
148
|
### Running Callbacks
|
122
149
|
|
123
150
|
In some cases a simple success or error result is not sufficient to describe the various results
|
data/lib/the_help/service.rb
CHANGED
@@ -194,8 +194,16 @@ module TheHelp
|
|
194
194
|
freeze
|
195
195
|
end
|
196
196
|
|
197
|
-
def error(value)
|
198
|
-
self.value =
|
197
|
+
def error(value = nil, &block)
|
198
|
+
self.value = if block_given?
|
199
|
+
begin
|
200
|
+
self.value = block.call
|
201
|
+
rescue StandardError => e
|
202
|
+
e
|
203
|
+
end
|
204
|
+
else
|
205
|
+
value
|
206
|
+
end
|
199
207
|
self.status = :error
|
200
208
|
freeze
|
201
209
|
end
|
data/lib/the_help/version.rb
CHANGED