bcdd-result 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +3 -13
- data/CHANGELOG.md +95 -2
- data/README.md +572 -18
- data/lib/bcdd/result/data.rb +12 -7
- data/lib/bcdd/result/error.rb +9 -1
- data/lib/bcdd/result/expectations/contract/disabled.rb +25 -0
- data/lib/bcdd/result/expectations/contract/evaluator.rb +45 -0
- data/lib/bcdd/result/expectations/contract/for_types.rb +29 -0
- data/lib/bcdd/result/expectations/contract/for_types_and_values.rb +37 -0
- data/lib/bcdd/result/expectations/contract/interface.rb +21 -0
- data/lib/bcdd/result/expectations/contract.rb +25 -0
- data/lib/bcdd/result/expectations/error.rb +15 -0
- data/lib/bcdd/result/expectations/mixin.rb +37 -0
- data/lib/bcdd/result/expectations/type_checker.rb +33 -0
- data/lib/bcdd/result/expectations.rb +50 -0
- data/lib/bcdd/result/failure.rb +1 -1
- data/lib/bcdd/result/handler/allowed_types.rb +45 -0
- data/lib/bcdd/result/handler.rb +13 -8
- data/lib/bcdd/result/mixin.rb +31 -4
- data/lib/bcdd/result/success.rb +1 -1
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +24 -19
- data/sig/bcdd/result.rbs +229 -40
- metadata +13 -3
- data/lib/bcdd/result/type.rb +0 -17
data/sig/bcdd/result.rbs
CHANGED
@@ -6,14 +6,20 @@ end
|
|
6
6
|
|
7
7
|
class BCDD::Result
|
8
8
|
private attr_accessor unknown: bool
|
9
|
+
private attr_reader type_checker: BCDD::Result::Expectations::TypeChecker
|
9
10
|
|
10
|
-
attr_reader
|
11
|
-
attr_reader value: untyped
|
11
|
+
attr_reader data: BCDD::Result::Data
|
12
12
|
attr_reader subject: untyped
|
13
13
|
|
14
|
-
def initialize: (
|
14
|
+
def initialize: (
|
15
|
+
type: Symbol,
|
16
|
+
value: untyped,
|
17
|
+
?subject: untyped,
|
18
|
+
?expectations: BCDD::Result::Expectations::Contract::Evaluator
|
19
|
+
) -> void
|
15
20
|
|
16
21
|
def type: -> Symbol
|
22
|
+
def value: -> untyped
|
17
23
|
|
18
24
|
def success?: (?Symbol type) -> bool
|
19
25
|
def failure?: (?Symbol type) -> bool
|
@@ -25,11 +31,9 @@ class BCDD::Result
|
|
25
31
|
def on_failure: (*Symbol) { (untyped, Symbol) -> void } -> BCDD::Result
|
26
32
|
def on_unknown: () { (untyped, Symbol) -> void } -> BCDD::Result
|
27
33
|
|
28
|
-
def and_then: (?Symbol method_name) { (untyped) -> untyped } -> BCDD::Result
|
34
|
+
def and_then: (?Symbol method_name, ?untyped context) ?{ (untyped) -> untyped } -> BCDD::Result
|
29
35
|
|
30
|
-
def handle: { (BCDD::Result::Handler) -> void } -> untyped
|
31
|
-
|
32
|
-
def data: -> BCDD::Result::Data
|
36
|
+
def handle: () { (BCDD::Result::Handler) -> void } -> untyped
|
33
37
|
|
34
38
|
def ==: (untyped) -> bool
|
35
39
|
def hash: -> Integer
|
@@ -45,7 +49,7 @@ class BCDD::Result
|
|
45
49
|
|
46
50
|
def name: -> Symbol
|
47
51
|
def known: (Proc) -> untyped
|
48
|
-
def call_subject_method: (Symbol) -> BCDD::Result
|
52
|
+
def call_subject_method: (Symbol, untyped) -> BCDD::Result
|
49
53
|
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result
|
50
54
|
end
|
51
55
|
|
@@ -65,44 +69,26 @@ end
|
|
65
69
|
|
66
70
|
class BCDD::Result
|
67
71
|
module Mixin
|
68
|
-
|
69
|
-
|
70
|
-
def Failure: (Symbol type, ?untyped value) -> BCDD::Result::Failure
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class BCDD::Result
|
75
|
-
class Handler
|
76
|
-
UNDEFINED: Object
|
72
|
+
module Methods
|
73
|
+
def Success: (Symbol type, ?untyped value) -> BCDD::Result::Success
|
77
74
|
|
78
|
-
|
75
|
+
def Failure: (Symbol type, ?untyped value) -> BCDD::Result::Failure
|
76
|
+
end
|
79
77
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
def unknown: () { (untyped, Symbol) -> void } -> untyped
|
78
|
+
module Addons
|
79
|
+
module Continuable
|
80
|
+
include BCDD::Result::Mixin::Methods
|
84
81
|
|
85
|
-
|
82
|
+
private def Continue: (untyped) -> BCDD::Result::Success
|
83
|
+
end
|
86
84
|
|
87
|
-
|
85
|
+
OPTIONS: Hash[Symbol, Module]
|
88
86
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
def outcome?: -> bool
|
93
|
-
def outcome=: (Proc) -> void
|
94
|
-
def outcome: -> untyped
|
87
|
+
def self.options: (Array[Symbol]) -> Array[Module]
|
88
|
+
end
|
95
89
|
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class BCDD::Result
|
99
|
-
class Type
|
100
|
-
attr_reader to_sym: Symbol
|
101
90
|
|
102
|
-
|
103
|
-
|
104
|
-
def in?: (Array[Symbol], allow_empty: bool) -> bool
|
105
|
-
end
|
91
|
+
def self.mixin: (?with: Array[Symbol]) -> Module
|
106
92
|
end
|
107
93
|
|
108
94
|
class BCDD::Result
|
@@ -113,7 +99,7 @@ class BCDD::Result
|
|
113
99
|
attr_reader to_h: Hash[Symbol, untyped]
|
114
100
|
attr_reader to_a: [Symbol, Symbol, untyped]
|
115
101
|
|
116
|
-
def initialize: (
|
102
|
+
def initialize: (Symbol, Symbol, untyped) -> void
|
117
103
|
|
118
104
|
def inspect: -> String
|
119
105
|
|
@@ -146,5 +132,208 @@ class BCDD::Result
|
|
146
132
|
def self.build: (subject: untyped, method: ::Method)
|
147
133
|
-> BCDD::Result::Error::WrongSubjectMethodArity
|
148
134
|
end
|
135
|
+
|
136
|
+
class UnhandledTypes < BCDD::Result::Error
|
137
|
+
def self.build: (types: Set[Symbol])
|
138
|
+
-> BCDD::Result::Error::UnhandledTypes
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class BCDD::Result
|
144
|
+
class Handler
|
145
|
+
UNDEFINED: Object
|
146
|
+
|
147
|
+
def initialize: (
|
148
|
+
BCDD::Result,
|
149
|
+
type_checker: BCDD::Result::Expectations::TypeChecker
|
150
|
+
) -> void
|
151
|
+
|
152
|
+
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
153
|
+
def failure: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
154
|
+
def success: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
155
|
+
def unknown: () { (untyped, Symbol) -> void } -> untyped
|
156
|
+
|
157
|
+
alias type []
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
attr_reader result: BCDD::Result
|
162
|
+
attr_reader allowed_types: BCDD::Result::Handler::AllowedTypes
|
163
|
+
|
164
|
+
def outcome?: -> bool
|
165
|
+
def outcome=: (Proc) -> void
|
166
|
+
def outcome: -> untyped
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class BCDD::Result::Handler
|
171
|
+
class AllowedTypes
|
172
|
+
attr_reader unchecked: Set[Symbol]
|
173
|
+
attr_reader type_checker: BCDD::Result::Expectations::TypeChecker
|
174
|
+
|
175
|
+
def initialize: (
|
176
|
+
BCDD::Result::Expectations::TypeChecker
|
177
|
+
) -> void
|
178
|
+
|
179
|
+
def allow?: (Array[Symbol]) -> bool
|
180
|
+
def allow_success?: (Array[Symbol]) -> bool
|
181
|
+
def allow_failure?: (Array[Symbol]) -> bool
|
182
|
+
|
183
|
+
def all_checked?: -> bool
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def check!: (Array[Symbol], bool) -> bool
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class BCDD::Result::Expectations
|
192
|
+
MIXIN_METHODS: String
|
193
|
+
|
194
|
+
def self.mixin: (
|
195
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
196
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
197
|
+
) -> Module
|
198
|
+
|
199
|
+
def self.evaluate: (
|
200
|
+
BCDD::Result::Data,
|
201
|
+
BCDD::Result::Expectations::Contract::Evaluator
|
202
|
+
) -> BCDD::Result::Expectations::TypeChecker
|
203
|
+
|
204
|
+
def initialize: (
|
205
|
+
?subject: untyped,
|
206
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
207
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
208
|
+
?contract: BCDD::Result::Expectations::Contract::Evaluator
|
209
|
+
) -> void
|
210
|
+
|
211
|
+
def Success: (Symbol, ?untyped) -> BCDD::Result::Success
|
212
|
+
def Failure: (Symbol, ?untyped) -> BCDD::Result::Failure
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
attr_reader subject: untyped
|
217
|
+
attr_reader contract: BCDD::Result::Expectations::Contract::Evaluator
|
218
|
+
end
|
219
|
+
|
220
|
+
module BCDD::Result::Expectations::Mixin
|
221
|
+
METHODS: String
|
222
|
+
|
223
|
+
module Addons
|
224
|
+
module Continuable
|
225
|
+
private def Continue: (untyped) -> BCDD::Result::Success
|
226
|
+
end
|
227
|
+
|
228
|
+
OPTIONS: Hash[Symbol, Module]
|
229
|
+
|
230
|
+
def self.options: (Array[Symbol]) -> Array[Module]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
module BCDD::Result::Expectations::Contract
|
235
|
+
NONE: BCDD::Result::Expectations::Contract::Evaluator
|
236
|
+
|
237
|
+
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol])
|
238
|
+
-> BCDD::Result::Expectations::Contract::Evaluator
|
239
|
+
|
240
|
+
def self.new: (
|
241
|
+
success: Hash[Symbol, untyped] | Array[Symbol],
|
242
|
+
failure: Hash[Symbol, untyped] | Array[Symbol]
|
243
|
+
) -> BCDD::Result::Expectations::Contract::Evaluator
|
244
|
+
end
|
245
|
+
|
246
|
+
class BCDD::Result::Expectations
|
247
|
+
class TypeChecker
|
248
|
+
attr_reader result_type: Symbol
|
249
|
+
attr_reader expectations: BCDD::Result::Expectations::Contract::Evaluator
|
250
|
+
|
251
|
+
def initialize: (
|
252
|
+
Symbol,
|
253
|
+
expectations: BCDD::Result::Expectations::Contract::Evaluator
|
254
|
+
) -> void
|
255
|
+
|
256
|
+
def allow?: (Array[Symbol]) -> bool
|
257
|
+
def allow_success?: (Array[Symbol]) -> bool
|
258
|
+
def allow_failure?: (Array[Symbol]) -> bool
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def validate: (
|
263
|
+
Array[Symbol],
|
264
|
+
expected: BCDD::Result::Expectations::Contract::Interface,
|
265
|
+
allow_empty: bool
|
266
|
+
) -> bool
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
class BCDD::Result::Expectations::Error < BCDD::Result::Error
|
271
|
+
class UnexpectedType < BCDD::Result::Expectations::Error
|
272
|
+
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
273
|
+
-> BCDD::Result::Expectations::Error::UnexpectedType
|
274
|
+
end
|
275
|
+
|
276
|
+
class UnexpectedValue < BCDD::Result::Expectations::Error
|
277
|
+
def self.build: (type: Symbol, value: untyped)
|
278
|
+
-> BCDD::Result::Expectations::Error::UnexpectedValue
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
module BCDD::Result::Expectations::Contract
|
283
|
+
module Interface
|
284
|
+
def ==: (BCDD::Result::Expectations::Contract::Interface) -> bool
|
285
|
+
|
286
|
+
def allowed_types: -> Set[Symbol]
|
287
|
+
|
288
|
+
def type?: (Symbol) -> bool
|
289
|
+
|
290
|
+
def type!: (Symbol) -> Symbol
|
291
|
+
|
292
|
+
def type_and_value!: (BCDD::Result::Data) -> void
|
293
|
+
|
294
|
+
def !=: (untyped) -> bool
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
module BCDD::Result::Expectations::Contract
|
299
|
+
module Disabled
|
300
|
+
extend Interface
|
301
|
+
|
302
|
+
EMPTY_SET: Set[Symbol]
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
module BCDD::Result::Expectations::Contract
|
307
|
+
class ForTypes
|
308
|
+
include Interface
|
309
|
+
|
310
|
+
def initialize: (Array[Symbol]) -> void
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
module BCDD::Result::Expectations::Contract
|
315
|
+
class ForTypesAndValues
|
316
|
+
include Interface
|
317
|
+
|
318
|
+
def initialize: (Hash[Symbol, untyped]) -> void
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
module BCDD::Result::Expectations::Contract
|
323
|
+
class Evaluator
|
324
|
+
include Interface
|
325
|
+
|
326
|
+
attr_reader allowed_types: Set[Symbol]
|
327
|
+
attr_reader success: BCDD::Result::Expectations::Contract::Interface
|
328
|
+
attr_reader failure: BCDD::Result::Expectations::Contract::Interface
|
329
|
+
|
330
|
+
def initialize: (
|
331
|
+
BCDD::Result::Expectations::Contract::Interface,
|
332
|
+
BCDD::Result::Expectations::Contract::Interface
|
333
|
+
) -> void
|
334
|
+
|
335
|
+
private
|
336
|
+
|
337
|
+
def for: (BCDD::Result::Data) -> BCDD::Result::Expectations::Contract::Interface
|
149
338
|
end
|
150
339
|
end
|
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.6.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: 2023-
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Empower Ruby apps with a pragmatic use of Railway Oriented Programming.
|
@@ -31,11 +31,21 @@ files:
|
|
31
31
|
- lib/bcdd/result.rb
|
32
32
|
- lib/bcdd/result/data.rb
|
33
33
|
- lib/bcdd/result/error.rb
|
34
|
+
- lib/bcdd/result/expectations.rb
|
35
|
+
- lib/bcdd/result/expectations/contract.rb
|
36
|
+
- lib/bcdd/result/expectations/contract/disabled.rb
|
37
|
+
- lib/bcdd/result/expectations/contract/evaluator.rb
|
38
|
+
- lib/bcdd/result/expectations/contract/for_types.rb
|
39
|
+
- lib/bcdd/result/expectations/contract/for_types_and_values.rb
|
40
|
+
- lib/bcdd/result/expectations/contract/interface.rb
|
41
|
+
- lib/bcdd/result/expectations/error.rb
|
42
|
+
- lib/bcdd/result/expectations/mixin.rb
|
43
|
+
- lib/bcdd/result/expectations/type_checker.rb
|
34
44
|
- lib/bcdd/result/failure.rb
|
35
45
|
- lib/bcdd/result/handler.rb
|
46
|
+
- lib/bcdd/result/handler/allowed_types.rb
|
36
47
|
- lib/bcdd/result/mixin.rb
|
37
48
|
- lib/bcdd/result/success.rb
|
38
|
-
- lib/bcdd/result/type.rb
|
39
49
|
- lib/bcdd/result/version.rb
|
40
50
|
- lib/result.rb
|
41
51
|
- sig/bcdd/result.rbs
|
data/lib/bcdd/result/type.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class BCDD::Result
|
4
|
-
class Type
|
5
|
-
attr_reader :to_sym
|
6
|
-
|
7
|
-
def initialize(type)
|
8
|
-
@to_sym = type.to_sym
|
9
|
-
end
|
10
|
-
|
11
|
-
def in?(types, allow_empty: false)
|
12
|
-
(allow_empty && types.empty?) || types.any?(to_sym)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private_constant :Type
|
17
|
-
end
|