bcdd-result 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -15
- data/README.md +221 -18
- data/lib/bcdd/result/callable_and_then/caller.rb +49 -0
- data/lib/bcdd/result/callable_and_then/config.rb +15 -0
- data/lib/bcdd/result/callable_and_then/error.rb +11 -0
- data/lib/bcdd/result/callable_and_then.rb +9 -0
- data/lib/bcdd/result/config/switchers/features.rb +5 -1
- data/lib/bcdd/result/config.rb +9 -3
- data/lib/bcdd/result/context/callable_and_then.rb +39 -0
- data/lib/bcdd/result/context/expectations/mixin.rb +2 -2
- data/lib/bcdd/result/context/mixin.rb +1 -1
- data/lib/bcdd/result/context/success.rb +12 -8
- data/lib/bcdd/result/context.rb +34 -16
- data/lib/bcdd/result/error.rb +20 -11
- data/lib/bcdd/result/expectations/mixin.rb +3 -3
- data/lib/bcdd/result/expectations.rb +6 -6
- data/lib/bcdd/result/mixin.rb +1 -1
- data/lib/bcdd/result/transitions/tracking/disabled.rb +14 -4
- data/lib/bcdd/result/transitions/tracking/enabled.rb +38 -18
- data/lib/bcdd/result/transitions/tree.rb +10 -6
- data/lib/bcdd/result/transitions.rb +8 -10
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +34 -19
- data/sig/bcdd/result/callable_and_then.rbs +60 -0
- data/sig/bcdd/result/config.rbs +2 -0
- data/sig/bcdd/result/context.rbs +56 -4
- data/sig/bcdd/result/error.rbs +9 -6
- data/sig/bcdd/result/expectations.rbs +4 -4
- data/sig/bcdd/result/transitions.rbs +16 -5
- data/sig/bcdd/result.rbs +9 -5
- metadata +8 -2
data/sig/bcdd/result/context.rbs
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
class BCDD::Result::Context < BCDD::Result
|
2
2
|
EXPECTED_OUTCOME: String
|
3
3
|
|
4
|
-
|
4
|
+
SourceMethodArity: ^(Method) -> Integer
|
5
5
|
|
6
6
|
attr_reader acc: Hash[Symbol, untyped]
|
7
7
|
|
8
8
|
def initialize: (
|
9
9
|
type: Symbol,
|
10
10
|
value: untyped,
|
11
|
-
?
|
11
|
+
?source: untyped,
|
12
12
|
?expectations: BCDD::Result::Contract::Evaluator,
|
13
13
|
?terminal: bool
|
14
14
|
) -> void
|
15
15
|
|
16
|
-
def and_then: (?Symbol, **untyped) ?{ (Hash[Symbol, untyped]) -> untyped } ->
|
16
|
+
def and_then: (?Symbol, **untyped) ?{ (Hash[Symbol, untyped]) -> untyped } -> untyped
|
17
|
+
|
18
|
+
def and_then!: (untyped, **untyped) -> untyped
|
17
19
|
|
18
20
|
private
|
19
21
|
|
20
|
-
def
|
22
|
+
def call_and_then_source_method: (Symbol, Hash[Symbol, untyped]) -> BCDD::Result::Context
|
23
|
+
|
24
|
+
def call_and_then_callable!: (untyped, value: untyped, injected_value: untyped, method_name: (Symbol | nil)) -> BCDD::Result::Context
|
25
|
+
|
21
26
|
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result::Context
|
22
27
|
|
23
28
|
def raise_unexpected_outcome_error: (BCDD::Result::Context | untyped, Symbol) -> void
|
@@ -33,6 +38,53 @@ class BCDD::Result::Context
|
|
33
38
|
def self.Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
34
39
|
end
|
35
40
|
|
41
|
+
module BCDD::Result::Context::CallableAndThen
|
42
|
+
class Caller < BCDD::Result::CallableAndThen::Caller
|
43
|
+
module KeyArgs
|
44
|
+
def self.parameters?: (untyped) -> bool
|
45
|
+
|
46
|
+
def self.invalid_arity: (untyped, Symbol) -> BCDD::Result::CallableAndThen::Error::InvalidArity
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.call: (
|
50
|
+
untyped source,
|
51
|
+
value: untyped,
|
52
|
+
injected_value: untyped,
|
53
|
+
method_name: (Symbol | nil),
|
54
|
+
) -> BCDD::Result::Context
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def self.call_proc!: (
|
59
|
+
untyped source,
|
60
|
+
Hash[Symbol, untyped] value,
|
61
|
+
nil injected_value
|
62
|
+
) -> BCDD::Result::Context
|
63
|
+
|
64
|
+
def self.call_method!: (
|
65
|
+
untyped source,
|
66
|
+
Method method,
|
67
|
+
Hash[Symbol, untyped] value,
|
68
|
+
nil injected_value
|
69
|
+
) -> BCDD::Result::Context
|
70
|
+
|
71
|
+
def self.callable_method: (
|
72
|
+
untyped source,
|
73
|
+
(Symbol | nil) method_name
|
74
|
+
) -> ::Method
|
75
|
+
|
76
|
+
def self.ensure_result_object: (
|
77
|
+
untyped source,
|
78
|
+
untyped value,
|
79
|
+
BCDD::Result::Context result
|
80
|
+
) -> BCDD::Result::Context
|
81
|
+
|
82
|
+
def self.expected_result_object: () -> singleton(BCDD::Result::Context)
|
83
|
+
|
84
|
+
def self.expected_outcome: () -> String
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
36
88
|
class BCDD::Result::Context
|
37
89
|
class Failure < BCDD::Result::Context
|
38
90
|
include BCDD::Result::Failure::Methods
|
data/sig/bcdd/result/error.rbs
CHANGED
@@ -13,19 +13,22 @@ class BCDD::Result
|
|
13
13
|
-> BCDD::Result::Error::UnexpectedOutcome
|
14
14
|
end
|
15
15
|
|
16
|
-
class
|
17
|
-
def self.build: (given_result: BCDD::Result,
|
18
|
-
-> BCDD::Result::Error::
|
16
|
+
class InvalidResultSource < BCDD::Result::Error
|
17
|
+
def self.build: (given_result: BCDD::Result, expected_source: untyped)
|
18
|
+
-> BCDD::Result::Error::InvalidResultSource
|
19
19
|
end
|
20
20
|
|
21
|
-
class
|
22
|
-
def self.build: (
|
23
|
-
-> BCDD::Result::Error::
|
21
|
+
class InvalidSourceMethodArity < BCDD::Result::Error
|
22
|
+
def self.build: (source: untyped, method: Method, max_arity: Integer)
|
23
|
+
-> BCDD::Result::Error::InvalidSourceMethodArity
|
24
24
|
end
|
25
25
|
|
26
26
|
class UnhandledTypes < BCDD::Result::Error
|
27
27
|
def self.build: (types: Set[Symbol])
|
28
28
|
-> BCDD::Result::Error::UnhandledTypes
|
29
29
|
end
|
30
|
+
|
31
|
+
class CallableAndThenDisabled < BCDD::Result::Error
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
@@ -16,14 +16,14 @@ class BCDD::Result::Expectations
|
|
16
16
|
def self.result_factory_without_expectations: -> singleton(BCDD::Result)
|
17
17
|
|
18
18
|
def self.new: (
|
19
|
-
?
|
19
|
+
?source: untyped,
|
20
20
|
?contract: BCDD::Result::Contract::Evaluator,
|
21
21
|
?terminal: bool,
|
22
22
|
**untyped
|
23
23
|
) -> (BCDD::Result::Expectations | untyped)
|
24
24
|
|
25
25
|
def initialize: (
|
26
|
-
?
|
26
|
+
?source: untyped,
|
27
27
|
?contract: BCDD::Result::Contract::Evaluator,
|
28
28
|
?terminal: bool,
|
29
29
|
**untyped
|
@@ -32,13 +32,13 @@ class BCDD::Result::Expectations
|
|
32
32
|
def Success: (Symbol, ?untyped) -> BCDD::Result::Success
|
33
33
|
def Failure: (Symbol, ?untyped) -> BCDD::Result::Failure
|
34
34
|
|
35
|
-
def with: (
|
35
|
+
def with: (source: untyped) -> BCDD::Result::Expectations
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def _ResultAs: (singleton(BCDD::Result), Symbol, untyped) -> untyped
|
40
40
|
|
41
|
-
attr_reader
|
41
|
+
attr_reader source: untyped
|
42
42
|
attr_reader contract: BCDD::Result::Contract::Evaluator
|
43
43
|
attr_reader terminal: bool
|
44
44
|
end
|
@@ -32,7 +32,8 @@ class BCDD::Result
|
|
32
32
|
def parent_value: () -> untyped
|
33
33
|
def current_value: () -> untyped
|
34
34
|
def insert: (untyped) -> Node
|
35
|
-
def insert!: (untyped) ->
|
35
|
+
def insert!: (untyped) -> Tree
|
36
|
+
def move_to!: (Node) -> Tree
|
36
37
|
def move_up!: (?Integer level) -> Tree
|
37
38
|
def move_down!: (?Integer level) -> Tree
|
38
39
|
def move_to_root!: () -> Tree
|
@@ -54,14 +55,17 @@ class BCDD::Result
|
|
54
55
|
private attr_accessor records: Array[Hash[Symbol, untyped]]
|
55
56
|
private attr_accessor root_started_at: Integer
|
56
57
|
|
57
|
-
def
|
58
|
-
def finish: (result: BCDD::Result) -> void
|
58
|
+
def exec: (String, String) { () -> untyped } -> BCDD::Result
|
59
59
|
def reset!: () -> void
|
60
60
|
def record: (BCDD::Result) -> void
|
61
61
|
def record_and_then: ((untyped), untyped, untyped) { () -> BCDD::Result } -> BCDD::Result
|
62
|
+
def reset_and_then!: () -> void
|
62
63
|
|
63
64
|
private
|
64
65
|
|
66
|
+
def start: (String, String) -> void
|
67
|
+
def finish: (BCDD::Result) -> void
|
68
|
+
|
65
69
|
TreeNodeValueNormalizer: ^(Integer, Array[untyped]) -> untyped
|
66
70
|
|
67
71
|
def root_start: (Array[untyped]) -> void
|
@@ -72,11 +76,16 @@ class BCDD::Result
|
|
72
76
|
end
|
73
77
|
|
74
78
|
module Disabled
|
75
|
-
def self.
|
76
|
-
def self.finish: (result: BCDD::Result) -> void
|
79
|
+
def self.exec: (String, String) { () -> untyped } -> BCDD::Result
|
77
80
|
def self.reset!: () -> void
|
78
81
|
def self.record: (BCDD::Result) -> void
|
79
82
|
def self.record_and_then: ((untyped), untyped, untyped) { () -> BCDD::Result } -> BCDD::Result
|
83
|
+
def self.reset_and_then!: () -> void
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def self.start: (String, String) -> void
|
88
|
+
def self.finish: (BCDD::Result) -> void
|
80
89
|
end
|
81
90
|
|
82
91
|
def self.instance: () -> (Enabled | singleton(Disabled))
|
@@ -84,6 +93,8 @@ class BCDD::Result
|
|
84
93
|
|
85
94
|
THREAD_VAR_NAME: Symbol
|
86
95
|
|
96
|
+
EnsureResult: ^(untyped) -> BCDD::Result
|
97
|
+
|
87
98
|
def self.tracking: () -> (Tracking::Enabled | singleton(Tracking::Disabled))
|
88
99
|
end
|
89
100
|
end
|
data/sig/bcdd/result.rbs
CHANGED
@@ -4,17 +4,18 @@ class BCDD::Result
|
|
4
4
|
private attr_reader type_checker: BCDD::Result::Contract::TypeChecker
|
5
5
|
|
6
6
|
attr_reader data: BCDD::Result::Data
|
7
|
-
attr_reader
|
7
|
+
attr_reader source: untyped
|
8
8
|
attr_reader terminal: bool
|
9
9
|
attr_reader transitions: Hash[Symbol, untyped]
|
10
10
|
|
11
11
|
def self.config: -> BCDD::Result::Config
|
12
12
|
def self.configuration: { (BCDD::Result::Config) -> void } -> BCDD::Result::Config
|
13
|
+
def self.transitions: { () -> untyped } -> BCDD::Result
|
13
14
|
|
14
15
|
def initialize: (
|
15
16
|
type: Symbol,
|
16
17
|
value: untyped,
|
17
|
-
?
|
18
|
+
?source: untyped,
|
18
19
|
?expectations: BCDD::Result::Contract::Evaluator,
|
19
20
|
?terminal: bool
|
20
21
|
) -> void
|
@@ -33,7 +34,9 @@ class BCDD::Result
|
|
33
34
|
def on_failure: (*Symbol) { (untyped, Symbol) -> void } -> BCDD::Result
|
34
35
|
def on_unknown: () { (untyped, Symbol) -> void } -> BCDD::Result
|
35
36
|
|
36
|
-
def and_then: (?Symbol method_name, ?untyped
|
37
|
+
def and_then: (?Symbol method_name, ?untyped injected_value) ?{ (untyped) -> untyped } -> untyped
|
38
|
+
|
39
|
+
def and_then!: (untyped, ?untyped injected_value, _call: (Symbol | nil)) -> untyped
|
37
40
|
|
38
41
|
def handle: () { (BCDD::Result::Handler) -> void } -> untyped
|
39
42
|
|
@@ -51,10 +54,11 @@ class BCDD::Result
|
|
51
54
|
|
52
55
|
def kind: -> Symbol
|
53
56
|
def known: (Proc) -> untyped
|
54
|
-
def
|
55
|
-
def
|
57
|
+
def call_and_then_source_method: (Symbol, untyped) -> BCDD::Result
|
58
|
+
def call_and_then_source_method!: (untyped, untyped) -> BCDD::Result
|
56
59
|
def call_and_then_block: (untyped) -> BCDD::Result
|
57
60
|
def call_and_then_block!: (untyped) -> BCDD::Result
|
61
|
+
def call_and_then_callable!: (untyped, value: untyped, injected_value: untyped, method_name: (Symbol | nil)) -> BCDD::Result
|
58
62
|
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result
|
59
63
|
end
|
60
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcdd-result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Empower Ruby apps with pragmatic use of Result pattern (monad), Railway
|
14
14
|
Oriented Programming, and B/CDD.
|
@@ -28,6 +28,10 @@ files:
|
|
28
28
|
- Steepfile
|
29
29
|
- lib/bcdd-result.rb
|
30
30
|
- lib/bcdd/result.rb
|
31
|
+
- lib/bcdd/result/callable_and_then.rb
|
32
|
+
- lib/bcdd/result/callable_and_then/caller.rb
|
33
|
+
- lib/bcdd/result/callable_and_then/config.rb
|
34
|
+
- lib/bcdd/result/callable_and_then/error.rb
|
31
35
|
- lib/bcdd/result/config.rb
|
32
36
|
- lib/bcdd/result/config/options.rb
|
33
37
|
- lib/bcdd/result/config/switcher.rb
|
@@ -36,6 +40,7 @@ files:
|
|
36
40
|
- lib/bcdd/result/config/switchers/features.rb
|
37
41
|
- lib/bcdd/result/config/switchers/pattern_matching.rb
|
38
42
|
- lib/bcdd/result/context.rb
|
43
|
+
- lib/bcdd/result/context/callable_and_then.rb
|
39
44
|
- lib/bcdd/result/context/expectations.rb
|
40
45
|
- lib/bcdd/result/context/expectations/mixin.rb
|
41
46
|
- lib/bcdd/result/context/failure.rb
|
@@ -67,6 +72,7 @@ files:
|
|
67
72
|
- lib/bcdd/result/transitions/tree.rb
|
68
73
|
- lib/bcdd/result/version.rb
|
69
74
|
- sig/bcdd/result.rbs
|
75
|
+
- sig/bcdd/result/callable_and_then.rbs
|
70
76
|
- sig/bcdd/result/config.rbs
|
71
77
|
- sig/bcdd/result/context.rbs
|
72
78
|
- sig/bcdd/result/contract.rbs
|