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: b3d2c0d825215ac4722f0ee1ba20103148d5f3787626033a587f53514dc2af5d
4
- data.tar.gz: f4ed4851b5c60ab9785c088ee9fb750e7fa2a1a9cd6091619a6d9eee86a039f7
3
+ metadata.gz: 921a91dfad0a5209cd658c5873125499865608102f75473a05e1ad73bbeeba73
4
+ data.tar.gz: dd00092b19845ef7f83750d70a8a62d9853eb28d4d7b4c0a3c2c388464caa28c
5
5
  SHA512:
6
- metadata.gz: 1d0e17cb7423b03e027e930fef1a563e7039913fbff0afbc177ea36373a942300444a3f759e8f200ee189c11f4ac96aec87bcc55a76bd12bd1f96af809139461
7
- data.tar.gz: db0e3aa8cc8f4593cd007b738806400d6b73e45c963adf99c43da414a20f669c06e31937ece72fdfefb45ab7045f16a75a0ab4f8dcb77d6c03fe5c406e0c558c
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 ok(result)
17
+ def nok(error)
10
18
  allocate.tap do |object|
11
19
  object.instance_eval do
12
- @ok = true
13
- @result = result
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 nok(error)
28
+ def ok(result)
21
29
  allocate.tap do |object|
22
30
  object.instance_eval do
23
- @ok = false
24
- @error = error
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
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../result'
4
+
5
+ Result = ExAequo::Base::Result
6
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ExAequo
4
4
  module Base
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.4'
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.2
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