ex_aequo_base 0.3.0 → 0.3.1

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: f92a77061871fa1b02dcfee2d0d9a5342313fc5c8b149ce986837703d30419c1
4
- data.tar.gz: c2ba2d3248de83b4bcd17cde7512a95917ef7a424bad93cdf4ff661bb65bf8b1
3
+ metadata.gz: 0ae7088c186aa04b585d985ecec0f602695cee0b6ec6e0c333242633440ffb9d
4
+ data.tar.gz: 40c5d9591388596ec3c1d6f2b251192da081c02854dabfd6c8fcb233766185ef
5
5
  SHA512:
6
- metadata.gz: 41bf821a4a87fbdbcbd2d5197caab778b0d3efd67ec30e740a974cbd2045e81295edb5fe302bc91a4948301083492016577979b8b769f127e149996be63c2ca9
7
- data.tar.gz: 570f9e2fdbfb7850a657cf49387d65271b281e2af1412b0d6c3a169327c54c24bf24c5b15435675f2dc68b2717d57e67c07845065617298c7b255f95273b453c
6
+ metadata.gz: a32aabc72664eef456004008c91fbe86107fabbcb5ab12afefa42775cd5e65e9f0bde4fcc2474e6dfae02f767ba260d079d5b4b460517965c210938378b26db7
7
+ data.tar.gz: 85ebe63094aedf4a8eaf42873842aae5b6512b3aedb6fc02604b6e3ed2b82c90b7cf243859f045da2228b855840260a1455dcd45e1f5d3d7c09b935525c6f7bd
@@ -9,6 +9,7 @@ require_relative 'function'
9
9
  require_relative 'import_none'
10
10
  require_relative 'open_struct'
11
11
  require_relative 'regexp'
12
+ require_relative 'result'
12
13
  require_relative 'string'
13
14
  require_relative 'to_proc'
14
15
  # require_relative 'match_data'
@@ -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,29 @@
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 ok? = @ok
17
+
18
+ def result
19
+ raise IllegalState, "must not invoke result on an error result" unless @ok
20
+ @result
21
+ end
22
+
23
+ def to_h
24
+ ok? ? {ok: true, result: @result} : {ok: false, error: @error}
25
+ end
26
+ end
27
+ end
28
+ end
29
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ExAequo
4
4
  module Base
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
7
  end
8
8
  # 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.0
4
+ version: 0.3.1
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