ex_aequo_base 0.3.0 → 0.3.2
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 +4 -4
- data/lib/ex_aequo/base/all.rb +1 -0
- data/lib/ex_aequo/base/result/class_methods.rb +39 -0
- data/lib/ex_aequo/base/result.rb +37 -0
- data/lib/ex_aequo/base/version.rb +1 -1
- metadata +3 -2
- data/lib/ex_aequo/base/string/colorize.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d2c0d825215ac4722f0ee1ba20103148d5f3787626033a587f53514dc2af5d
|
4
|
+
data.tar.gz: f4ed4851b5c60ab9785c088ee9fb750e7fa2a1a9cd6091619a6d9eee86a039f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0e17cb7423b03e027e930fef1a563e7039913fbff0afbc177ea36373a942300444a3f759e8f200ee189c11f4ac96aec87bcc55a76bd12bd1f96af809139461
|
7
|
+
data.tar.gz: db0e3aa8cc8f4593cd007b738806400d6b73e45c963adf99c43da414a20f669c06e31937ece72fdfefb45ab7045f16a75a0ab4f8dcb77d6c03fe5c406e0c558c
|
data/lib/ex_aequo/base/all.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Base
|
5
|
+
class Result
|
6
|
+
module ClassMethods
|
7
|
+
def new(*, **) = raise NoMethodError, "undefined method 'new' for #<Class:Result>"
|
8
|
+
|
9
|
+
def ok(result)
|
10
|
+
allocate.tap do |object|
|
11
|
+
object.instance_eval do
|
12
|
+
@ok = true
|
13
|
+
@result = result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :success, :ok
|
19
|
+
|
20
|
+
def nok(error)
|
21
|
+
allocate.tap do |object|
|
22
|
+
object.instance_eval do
|
23
|
+
@ok = false
|
24
|
+
@error = error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :failure, :nok
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
extend ClassMethods
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'result/class_methods'
|
4
|
+
module ExAequo
|
5
|
+
module Base
|
6
|
+
class Result
|
7
|
+
IllegalState = Class.new(RuntimeError)
|
8
|
+
|
9
|
+
def deconstruct_keys(*) = {ok: @ok, result: @result, error: @error}
|
10
|
+
|
11
|
+
def error
|
12
|
+
raise IllegalState, "must not invoke error on an ok result" if @ok
|
13
|
+
@error
|
14
|
+
end
|
15
|
+
|
16
|
+
def if_failure(&blk)
|
17
|
+
blk.(@error) unless ok?
|
18
|
+
end
|
19
|
+
|
20
|
+
def if_success(&blk)
|
21
|
+
blk.(@result) if ok?
|
22
|
+
end
|
23
|
+
|
24
|
+
def ok? = @ok
|
25
|
+
|
26
|
+
def result
|
27
|
+
raise IllegalState, "must not invoke result on an error result" unless @ok
|
28
|
+
@result
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_h
|
32
|
+
ok? ? {ok: true, result: @result} : {ok: false, error: @error}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -70,8 +70,9 @@ files:
|
|
70
70
|
- lib/ex_aequo/base/none.rb
|
71
71
|
- lib/ex_aequo/base/open_struct.rb
|
72
72
|
- lib/ex_aequo/base/regexp.rb
|
73
|
+
- lib/ex_aequo/base/result.rb
|
74
|
+
- lib/ex_aequo/base/result/class_methods.rb
|
73
75
|
- lib/ex_aequo/base/string.rb
|
74
|
-
- lib/ex_aequo/base/string/colorize.rb
|
75
76
|
- lib/ex_aequo/base/to_proc.rb
|
76
77
|
- lib/ex_aequo/base/to_proc/false_class.rb
|
77
78
|
- lib/ex_aequo/base/to_proc/nil_class.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../colorize/colorizer'
|
4
|
-
class String
|
5
|
-
def colored(color, reset: true)
|
6
|
-
colors = [color, self, (reset ? :reset : nil)].compact
|
7
|
-
Colorize::Colorizer.colored(*colors)
|
8
|
-
end
|
9
|
-
|
10
|
-
def pcolored(color, device: $stdout) = Colorize::Colorizer.pcolored(color, self, device:)
|
11
|
-
end
|
12
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|