to-result 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/to_result.rb +14 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07abb60c2975a418781ae77cfc53ae596fc8e559ab270b81837719dc10967493
4
- data.tar.gz: ed6e2b66cea364e686d4fd37ddc8c98973e89a2ffcacaaa627f7bb060c9a4a4e
3
+ metadata.gz: 0bf957670d51788e15be5797daeb430d409cc38967e9f3ba93027ce66eefe93c
4
+ data.tar.gz: 5500df2709d9dd14780e53858cf6a2a10fe029d90d3c097e11280104983fdf44
5
5
  SHA512:
6
- metadata.gz: 3fef23d1986e562ea127f7f2d61f200ff3b1b1b8cc71a9b892919b84211c87b120f0af7c61ee53abc4aeb6f191ca71865f4004208ebd4e7956064f7de55f80bf
7
- data.tar.gz: '0895b62c8e0d5ee2b4834e265964baa684712f57119f6b95b5793b510f76f44ff6facf4e2a8c3b959c4a894ab9ccb590f0178712bd66fb65070c040459d76019'
6
+ metadata.gz: 80580831a173303c62330c741bccaa6bb6edad1155ef9639e33c4e1076132cff165b0a7a9d6d91d2a9d472a69841c3f6fd7af9ab177edcbc6488e8d34d958c14
7
+ data.tar.gz: 92eda88e706fbe5b330a5417190904d158487e469c726e64d07380e334efb07b9f30def99a2e6f19fa3e354d184cd9892287d18f02dbffe2130cadf5f351abf4
data/lib/to_result.rb CHANGED
@@ -3,14 +3,25 @@ require 'dry/monads'
3
3
  module ToResultMixin
4
4
  include Dry::Monads[:do, :result, :try]
5
5
 
6
+ #
7
+ # ToResult executes a block of code and returns Success or Failure.
8
+ # All exceptions inherited from StandardError are catched and
9
+ # converted to Failure or you can pass a list of exceptions to catch.
10
+ #
11
+ # @param [Array<Class>] exceptions
12
+ # @param [Proc] &f
13
+ #
14
+ # @return [Success]
15
+ # @return [Failure]
16
+ #
6
17
  def ToResult(exceptions = [StandardError], &f)
7
- Dry::Monads::Try.run(
8
- [StandardError],
18
+ Try.run(
19
+ exceptions,
9
20
  Proc.new do
10
21
  f.call
11
22
  rescue Dry::Monads::Do::Halt => e
12
23
  return e.result
13
- rescue StandardError => e
24
+ rescue *exceptions => e
14
25
  raise e
15
26
  end
16
27
  ).to_result
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to-result
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Toscano