ex_aequo_base 0.3.2 → 0.3.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921a91dfad0a5209cd658c5873125499865608102f75473a05e1ad73bbeeba73
|
4
|
+
data.tar.gz: dd00092b19845ef7f83750d70a8a62d9853eb28d4d7b4c0a3c2c388464caa28c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3d653eb3ff3614070315f27a291418fab629056d06abbb7fc89585b2f886fc69afd52765110c35460458d2a43137e3a57245af1d43edf7fc1f0e4674add052
|
7
|
+
data.tar.gz: 68739fd0703c6f97cd4f6d00a7738d47ad0917c390f720c1ce884f906276ba43e2a05e9c46fc10936668b85d735ca6556117427dcad46770550c0d366ba75513
|
@@ -4,29 +4,36 @@ module ExAequo
|
|
4
4
|
module Base
|
5
5
|
class Result
|
6
6
|
module ClassMethods
|
7
|
+
def from_value(value, error: nil)
|
8
|
+
if value
|
9
|
+
ok(value)
|
10
|
+
else
|
11
|
+
nok(error)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
def new(*, **) = raise NoMethodError, "undefined method 'new' for #<Class:Result>"
|
8
16
|
|
9
|
-
def
|
17
|
+
def nok(error)
|
10
18
|
allocate.tap do |object|
|
11
19
|
object.instance_eval do
|
12
|
-
@ok =
|
13
|
-
@
|
20
|
+
@ok = false
|
21
|
+
@error = error
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
25
|
+
alias_method :failure, :nok
|
17
26
|
|
18
|
-
alias_method :success, :ok
|
19
27
|
|
20
|
-
def
|
28
|
+
def ok(result)
|
21
29
|
allocate.tap do |object|
|
22
30
|
object.instance_eval do
|
23
|
-
@ok =
|
24
|
-
@
|
31
|
+
@ok = true
|
32
|
+
@result = result
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
28
|
-
|
29
|
-
alias_method :failure, :nok
|
36
|
+
alias_method :success, :ok
|
30
37
|
|
31
38
|
end
|
32
39
|
|
data/lib/ex_aequo/base/result.rb
CHANGED
@@ -13,6 +13,13 @@ module ExAequo
|
|
13
13
|
@error
|
14
14
|
end
|
15
15
|
|
16
|
+
def extract(&blk)
|
17
|
+
return @result if @ok
|
18
|
+
|
19
|
+
raise IllegalState, "must not extract from a failure result without a block (#{@error})" unless blk
|
20
|
+
blk.()
|
21
|
+
end
|
22
|
+
|
16
23
|
def if_failure(&blk)
|
17
24
|
blk.(@error) unless ok?
|
18
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ex_aequo_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/ex_aequo/base/regexp.rb
|
73
73
|
- lib/ex_aequo/base/result.rb
|
74
74
|
- lib/ex_aequo/base/result/class_methods.rb
|
75
|
+
- lib/ex_aequo/base/result/import.rb
|
75
76
|
- lib/ex_aequo/base/string.rb
|
76
77
|
- lib/ex_aequo/base/to_proc.rb
|
77
78
|
- lib/ex_aequo/base/to_proc/false_class.rb
|