to-result 0.0.1

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 +7 -0
  2. data/lib/to_result.rb +18 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07abb60c2975a418781ae77cfc53ae596fc8e559ab270b81837719dc10967493
4
+ data.tar.gz: ed6e2b66cea364e686d4fd37ddc8c98973e89a2ffcacaaa627f7bb060c9a4a4e
5
+ SHA512:
6
+ metadata.gz: 3fef23d1986e562ea127f7f2d61f200ff3b1b1b8cc71a9b892919b84211c87b120f0af7c61ee53abc4aeb6f191ca71865f4004208ebd4e7956064f7de55f80bf
7
+ data.tar.gz: '0895b62c8e0d5ee2b4834e265964baa684712f57119f6b95b5793b510f76f44ff6facf4e2a8c3b959c4a894ab9ccb590f0178712bd66fb65070c040459d76019'
data/lib/to_result.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'dry/monads'
2
+
3
+ module ToResultMixin
4
+ include Dry::Monads[:do, :result, :try]
5
+
6
+ def ToResult(exceptions = [StandardError], &f)
7
+ Dry::Monads::Try.run(
8
+ [StandardError],
9
+ Proc.new do
10
+ f.call
11
+ rescue Dry::Monads::Do::Halt => e
12
+ return e.result
13
+ rescue StandardError => e
14
+ raise e
15
+ end
16
+ ).to_result
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to-result
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christian Toscano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A wrapper over dry-monads to offer a handy and consistent way to implement
14
+ the Railway pattern.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/to_result.rb
21
+ homepage: https://github.com/a-chris/to-result
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.2.22
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A wrapper over dry-monads to offer a handy and consistent way to implement
44
+ the Railway pattern.
45
+ test_files: []