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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58c4ca451c960bbd6f54ee05d9a786db32365e8630cd57d1730d21b1e23b4b28
4
- data.tar.gz: d6b16972071beed84aebb226bf77be94e8e04bdc38ea8eb452170da903287e05
3
+ metadata.gz: 7c3bac0cd5079035a765ff1018c38020e8f7805b00fd0e7123da0a9fe2547e15
4
+ data.tar.gz: 7708a7c8c5523525b6ee909bd1395b03b898f69bb4fdab7e91b14fe6817e332c
5
5
  SHA512:
6
- metadata.gz: 31854f6f5c438280a532d0f9674f10409873164fa240b06716939972d72dd28de48244dc9ab0b160d5714d9c351d5f37da2323cbf33780bcf4c62d23aeadbf2b
7
- data.tar.gz: 59f1e173753355dbbaec54c1d4411c49184ff769e3a84061c5f81413e634761a9b959b86d8ffe9ff86bc54c3b2b316671bd75f477ee3fe693e7fbf7883ba6671
6
+ metadata.gz: a2a35d48df57043c329f3425539ca6e8aa181bd2f9b420977c5d871caab068d1a100ad8ae2d9b924dd56022340e0c0f4c5cb4587e510955627b9db428a4c2a9b
7
+ data.tar.gz: b91c4d0a6601a062987b77fbdb53760959b20332d8a071b216087568b1934ef99d5cd7e72dc19ecda5074c468e6d601154386a85f8c1e711aa69772b75e4433c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- the_help (3.0.0)
4
+ the_help (3.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -194,8 +194,16 @@ module TheHelp
194
194
  freeze
195
195
  end
196
196
 
197
- def error(value)
198
- self.value = 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheHelp
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wilger