corindon 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/corindon/dependency_injection/container.rb +1 -1
- data/lib/corindon/result/errors/bad_return_type_error.rb +19 -0
- data/lib/corindon/result/errors/result_error.rb +10 -0
- data/lib/corindon/result/ext.rb +25 -0
- data/lib/corindon/result/failure.rb +22 -0
- data/lib/corindon/result/result.rb +24 -0
- data/lib/corindon/result/success.rb +34 -0
- data/lib/corindon/{ext/something.rb → something/ext.rb} +2 -2
- data/lib/corindon/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae37025ed53b2bec8d329d9d640d40425406a0c6b2ba8fcf85ec573e5b0cdd6d
|
4
|
+
data.tar.gz: 3d6c2d3acac3f22c5c15b5128a3a7e005a4f1c6ea1508472d29bdcfb5eefc19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d44b60b7a78a391211c194a62b1cabf76664dc2a2f2ab268bc716873468c7e9245f2c6acd18c344596d16b48e3b16ce8f1de028e3a8f30de6adc042f7e8dc9
|
7
|
+
data.tar.gz: 704342b6b6afe491f9c21f9de07841356edc8c02e504ac66646d195fc88b34733f65dfa3a25a0b0f6ab40927429a11e2dec640c2cbf6a5861fc0a2926dca0b37
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
module Errors
|
6
|
+
class BadReturnTypeError < ResultError
|
7
|
+
# @return [Object]
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
# @param [Object] value
|
11
|
+
def initialize(value)
|
12
|
+
super("Expected a Result, got #{value}")
|
13
|
+
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
module Ext
|
6
|
+
refine Object do
|
7
|
+
def rescue_failure(&block)
|
8
|
+
block.call
|
9
|
+
rescue StandardError => error
|
10
|
+
Corindon::Result::Failure.new(error)
|
11
|
+
end
|
12
|
+
|
13
|
+
# rubocop:disable Naming/MethodName
|
14
|
+
def Failure(error)
|
15
|
+
Corindon::Result::Failure.new(error)
|
16
|
+
end
|
17
|
+
|
18
|
+
def Success(value)
|
19
|
+
Corindon::Result::Success.new(value)
|
20
|
+
end
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Failure < Result
|
6
|
+
# @return [Exception]
|
7
|
+
attr_reader :error
|
8
|
+
|
9
|
+
# @param [Exception] error
|
10
|
+
def initialize(error)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@error = error
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Boolean]
|
17
|
+
def failure?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Result
|
6
|
+
# @return [Boolean]
|
7
|
+
def success?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Boolean]
|
12
|
+
def failure?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
# @yieldparam [Object] value
|
17
|
+
# @yieldreturn [Result]
|
18
|
+
# @return [Result]
|
19
|
+
def and_then(&_block)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Success < Result
|
6
|
+
# @return [Object]
|
7
|
+
attr_reader :value
|
8
|
+
|
9
|
+
# @param [Object] value
|
10
|
+
def initialize(value)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Boolean]
|
17
|
+
def success?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def and_then(&block)
|
22
|
+
retval = block.call(value)
|
23
|
+
|
24
|
+
if retval.is_a?(Result)
|
25
|
+
retval
|
26
|
+
else
|
27
|
+
Failure.new(Errors::BadReturnTypeError.new(retval))
|
28
|
+
end
|
29
|
+
rescue StandardError => error
|
30
|
+
Failure.new(error)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/corindon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corindon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Piotaix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semantic
|
@@ -106,7 +106,13 @@ files:
|
|
106
106
|
- lib/corindon/dependency_injection/token/value_token.rb
|
107
107
|
- lib/corindon/ext/guards.rb
|
108
108
|
- lib/corindon/ext/guards/error.rb
|
109
|
-
- lib/corindon/
|
109
|
+
- lib/corindon/result/errors/bad_return_type_error.rb
|
110
|
+
- lib/corindon/result/errors/result_error.rb
|
111
|
+
- lib/corindon/result/ext.rb
|
112
|
+
- lib/corindon/result/failure.rb
|
113
|
+
- lib/corindon/result/result.rb
|
114
|
+
- lib/corindon/result/success.rb
|
115
|
+
- lib/corindon/something/ext.rb
|
110
116
|
- lib/corindon/version.rb
|
111
117
|
homepage: https://gitlab.com/piotaixr/corindon
|
112
118
|
licenses:
|