bcdd-result 0.6.0 → 0.8.0
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/.rubocop.yml +31 -11
- data/CHANGELOG.md +148 -0
- data/README.md +849 -242
- data/Rakefile +9 -3
- data/Steepfile +1 -1
- data/lib/bcdd/result/config/constant_alias.rb +33 -0
- data/lib/bcdd/result/config/options.rb +26 -0
- data/lib/bcdd/result/config/switcher.rb +82 -0
- data/lib/bcdd/result/config.rb +71 -0
- data/lib/bcdd/result/context/expectations/mixin.rb +23 -0
- data/lib/bcdd/result/context/expectations.rb +25 -0
- data/lib/bcdd/result/context/failure.rb +9 -0
- data/lib/bcdd/result/context/mixin.rb +41 -0
- data/lib/bcdd/result/context/success.rb +15 -0
- data/lib/bcdd/result/context.rb +74 -0
- data/lib/bcdd/result/{expectations/contract → contract}/disabled.rb +2 -2
- data/lib/bcdd/result/{expectations → contract}/error.rb +5 -3
- data/lib/bcdd/result/{expectations/contract → contract}/evaluator.rb +2 -2
- data/lib/bcdd/result/{expectations/contract → contract}/for_types.rb +2 -2
- data/lib/bcdd/result/contract/for_types_and_values.rb +44 -0
- data/lib/bcdd/result/contract/interface.rb +21 -0
- data/lib/bcdd/result/{expectations → contract}/type_checker.rb +1 -1
- data/lib/bcdd/result/contract.rb +33 -0
- data/lib/bcdd/result/error.rb +7 -9
- data/lib/bcdd/result/expectations/mixin.rb +19 -12
- data/lib/bcdd/result/expectations.rb +51 -36
- data/lib/bcdd/result/failure/methods.rb +21 -0
- data/lib/bcdd/result/failure.rb +2 -16
- data/lib/bcdd/result/mixin.rb +26 -8
- data/lib/bcdd/result/success/methods.rb +21 -0
- data/lib/bcdd/result/success.rb +2 -16
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +17 -4
- data/lib/bcdd-result.rb +3 -0
- data/sig/bcdd/result.rbs +340 -88
- metadata +27 -16
- data/lib/bcdd/result/expectations/contract/for_types_and_values.rb +0 -37
- data/lib/bcdd/result/expectations/contract/interface.rb +0 -21
- data/lib/bcdd/result/expectations/contract.rb +0 -25
- data/lib/result.rb +0 -5
data/sig/bcdd/result.rbs
CHANGED
@@ -6,16 +6,19 @@ end
|
|
6
6
|
|
7
7
|
class BCDD::Result
|
8
8
|
private attr_accessor unknown: bool
|
9
|
-
private attr_reader type_checker: BCDD::Result::
|
9
|
+
private attr_reader type_checker: BCDD::Result::Contract::TypeChecker
|
10
10
|
|
11
11
|
attr_reader data: BCDD::Result::Data
|
12
12
|
attr_reader subject: untyped
|
13
13
|
|
14
|
+
def self.config: -> BCDD::Result::Config
|
15
|
+
def self.configuration: { (BCDD::Result::Config) -> void } -> BCDD::Result::Config
|
16
|
+
|
14
17
|
def initialize: (
|
15
18
|
type: Symbol,
|
16
19
|
value: untyped,
|
17
20
|
?subject: untyped,
|
18
|
-
?expectations: BCDD::Result::
|
21
|
+
?expectations: BCDD::Result::Contract::Evaluator
|
19
22
|
) -> void
|
20
23
|
|
21
24
|
def type: -> Symbol
|
@@ -31,7 +34,7 @@ class BCDD::Result
|
|
31
34
|
def on_failure: (*Symbol) { (untyped, Symbol) -> void } -> BCDD::Result
|
32
35
|
def on_unknown: () { (untyped, Symbol) -> void } -> BCDD::Result
|
33
36
|
|
34
|
-
def and_then: (?Symbol method_name, ?untyped context) ?{ (untyped) -> untyped } ->
|
37
|
+
def and_then: (?Symbol method_name, ?untyped context) ?{ (untyped) -> untyped } -> untyped
|
35
38
|
|
36
39
|
def handle: () { (BCDD::Result::Handler) -> void } -> untyped
|
37
40
|
|
@@ -54,21 +57,50 @@ class BCDD::Result
|
|
54
57
|
end
|
55
58
|
|
56
59
|
class BCDD::Result
|
57
|
-
class
|
60
|
+
class Success < BCDD::Result
|
61
|
+
module Methods
|
62
|
+
def success?: (?Symbol type) -> bool
|
63
|
+
def failure?: (?Symbol type) -> bool
|
64
|
+
def value_or: { () -> untyped } -> untyped
|
65
|
+
def value: -> untyped
|
66
|
+
|
67
|
+
private
|
68
|
+
def name: -> Symbol
|
69
|
+
def type_checker: -> BCDD::Result::Contract::TypeChecker
|
70
|
+
end
|
71
|
+
|
72
|
+
include Methods
|
58
73
|
end
|
59
74
|
|
60
|
-
def self.
|
75
|
+
def self.Failure: (Symbol type, ?untyped value) -> BCDD::Result::Failure
|
61
76
|
end
|
62
77
|
|
78
|
+
|
63
79
|
class BCDD::Result
|
64
|
-
class
|
80
|
+
class Failure < BCDD::Result
|
81
|
+
module Methods
|
82
|
+
def success?: (?Symbol type) -> bool
|
83
|
+
def failure?: (?Symbol type) -> bool
|
84
|
+
def value_or: { (untyped) -> untyped } -> untyped
|
85
|
+
def value: -> untyped
|
86
|
+
|
87
|
+
private
|
88
|
+
def name: -> Symbol
|
89
|
+
def type_checker: -> BCDD::Result::Contract::TypeChecker
|
90
|
+
end
|
91
|
+
|
92
|
+
include Methods
|
65
93
|
end
|
66
94
|
|
67
|
-
def self.
|
95
|
+
def self.Success: (Symbol type, ?untyped value) -> BCDD::Result::Success
|
68
96
|
end
|
69
97
|
|
70
98
|
class BCDD::Result
|
71
99
|
module Mixin
|
100
|
+
module Factory
|
101
|
+
def self.module!: -> Module
|
102
|
+
end
|
103
|
+
|
72
104
|
module Methods
|
73
105
|
def Success: (Symbol type, ?untyped value) -> BCDD::Result::Success
|
74
106
|
|
@@ -79,16 +111,22 @@ class BCDD::Result
|
|
79
111
|
module Continuable
|
80
112
|
include BCDD::Result::Mixin::Methods
|
81
113
|
|
82
|
-
private
|
114
|
+
private
|
115
|
+
|
116
|
+
def Continue: (untyped) -> BCDD::Result::Success
|
83
117
|
end
|
84
118
|
|
85
119
|
OPTIONS: Hash[Symbol, Module]
|
86
120
|
|
87
|
-
def self.options: (
|
121
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
|
88
122
|
end
|
89
123
|
end
|
90
124
|
|
91
|
-
def self.mixin: (?
|
125
|
+
def self.mixin: (?config: Hash[Symbol, Hash[Symbol, bool]]) -> Module
|
126
|
+
|
127
|
+
def self.mixin_module: -> singleton(BCDD::Result::Mixin)
|
128
|
+
|
129
|
+
def self.result_factory: -> singleton(BCDD::Result)
|
92
130
|
end
|
93
131
|
|
94
132
|
class BCDD::Result
|
@@ -109,7 +147,7 @@ class BCDD::Result
|
|
109
147
|
end
|
110
148
|
|
111
149
|
class BCDD::Result
|
112
|
-
class Error <
|
150
|
+
class Error < StandardError
|
113
151
|
def self.build: (**untyped) -> BCDD::Result::Error
|
114
152
|
|
115
153
|
class NotImplemented < BCDD::Result::Error
|
@@ -119,18 +157,18 @@ class BCDD::Result
|
|
119
157
|
end
|
120
158
|
|
121
159
|
class UnexpectedOutcome < BCDD::Result::Error
|
122
|
-
def self.build: (outcome: untyped, origin: Symbol)
|
160
|
+
def self.build: (outcome: untyped, origin: Symbol, ?expected: String)
|
123
161
|
-> BCDD::Result::Error::UnexpectedOutcome
|
124
162
|
end
|
125
163
|
|
126
|
-
class
|
164
|
+
class InvalidResultSubject < BCDD::Result::Error
|
127
165
|
def self.build: (given_result: BCDD::Result, expected_subject: untyped)
|
128
|
-
-> BCDD::Result::Error::
|
166
|
+
-> BCDD::Result::Error::InvalidResultSubject
|
129
167
|
end
|
130
168
|
|
131
|
-
class
|
132
|
-
def self.build: (subject: untyped, method:
|
133
|
-
-> BCDD::Result::Error::
|
169
|
+
class InvalidSubjectMethodArity < BCDD::Result::Error
|
170
|
+
def self.build: (subject: untyped, method: Method, max_arity: Integer)
|
171
|
+
-> BCDD::Result::Error::InvalidSubjectMethodArity
|
134
172
|
end
|
135
173
|
|
136
174
|
class UnhandledTypes < BCDD::Result::Error
|
@@ -146,7 +184,7 @@ class BCDD::Result
|
|
146
184
|
|
147
185
|
def initialize: (
|
148
186
|
BCDD::Result,
|
149
|
-
type_checker: BCDD::Result::
|
187
|
+
type_checker: BCDD::Result::Contract::TypeChecker
|
150
188
|
) -> void
|
151
189
|
|
152
190
|
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
@@ -170,10 +208,10 @@ end
|
|
170
208
|
class BCDD::Result::Handler
|
171
209
|
class AllowedTypes
|
172
210
|
attr_reader unchecked: Set[Symbol]
|
173
|
-
attr_reader type_checker: BCDD::Result::
|
211
|
+
attr_reader type_checker: BCDD::Result::Contract::TypeChecker
|
174
212
|
|
175
213
|
def initialize: (
|
176
|
-
BCDD::Result::
|
214
|
+
BCDD::Result::Contract::TypeChecker
|
177
215
|
) -> void
|
178
216
|
|
179
217
|
def allow?: (Array[Symbol]) -> bool
|
@@ -188,69 +226,32 @@ class BCDD::Result::Handler
|
|
188
226
|
end
|
189
227
|
end
|
190
228
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
def self.mixin: (
|
195
|
-
?success: Hash[Symbol, untyped] | Array[Symbol],
|
196
|
-
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
197
|
-
) -> Module
|
229
|
+
module BCDD::Result::Contract
|
230
|
+
NONE: BCDD::Result::Contract::Evaluator
|
198
231
|
|
199
232
|
def self.evaluate: (
|
200
233
|
BCDD::Result::Data,
|
201
|
-
BCDD::Result::
|
202
|
-
) -> BCDD::Result::
|
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
|
234
|
+
BCDD::Result::Contract::Evaluator
|
235
|
+
) -> BCDD::Result::Contract::TypeChecker
|
233
236
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol])
|
238
|
-
-> BCDD::Result::Expectations::Contract::Evaluator
|
237
|
+
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol], Hash[Symbol, Hash[Symbol, bool]])
|
238
|
+
-> BCDD::Result::Contract::Interface
|
239
239
|
|
240
240
|
def self.new: (
|
241
241
|
success: Hash[Symbol, untyped] | Array[Symbol],
|
242
|
-
failure: Hash[Symbol, untyped] | Array[Symbol]
|
243
|
-
|
242
|
+
failure: Hash[Symbol, untyped] | Array[Symbol],
|
243
|
+
config: Hash[Symbol, Hash[Symbol, bool]]
|
244
|
+
) -> BCDD::Result::Contract::Evaluator
|
244
245
|
end
|
245
246
|
|
246
|
-
|
247
|
+
module BCDD::Result::Contract
|
247
248
|
class TypeChecker
|
248
249
|
attr_reader result_type: Symbol
|
249
|
-
attr_reader expectations: BCDD::Result::
|
250
|
+
attr_reader expectations: BCDD::Result::Contract::Evaluator
|
250
251
|
|
251
252
|
def initialize: (
|
252
253
|
Symbol,
|
253
|
-
expectations: BCDD::Result::
|
254
|
+
expectations: BCDD::Result::Contract::Evaluator
|
254
255
|
) -> void
|
255
256
|
|
256
257
|
def allow?: (Array[Symbol]) -> bool
|
@@ -261,27 +262,27 @@ class BCDD::Result::Expectations
|
|
261
262
|
|
262
263
|
def validate: (
|
263
264
|
Array[Symbol],
|
264
|
-
expected: BCDD::Result::
|
265
|
+
expected: BCDD::Result::Contract::Interface,
|
265
266
|
allow_empty: bool
|
266
267
|
) -> bool
|
267
268
|
end
|
268
269
|
end
|
269
270
|
|
270
|
-
class BCDD::Result::
|
271
|
-
class UnexpectedType < BCDD::Result::
|
271
|
+
class BCDD::Result::Contract::Error < BCDD::Result::Error
|
272
|
+
class UnexpectedType < BCDD::Result::Contract::Error
|
272
273
|
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
273
|
-
-> BCDD::Result::
|
274
|
+
-> BCDD::Result::Contract::Error::UnexpectedType
|
274
275
|
end
|
275
276
|
|
276
|
-
class UnexpectedValue < BCDD::Result::
|
277
|
-
def self.build: (type: Symbol, value: untyped)
|
278
|
-
-> BCDD::Result::
|
277
|
+
class UnexpectedValue < BCDD::Result::Contract::Error
|
278
|
+
def self.build: (type: Symbol, value: untyped, ?cause: Exception)
|
279
|
+
-> BCDD::Result::Contract::Error::UnexpectedValue
|
279
280
|
end
|
280
281
|
end
|
281
282
|
|
282
|
-
module BCDD::Result::
|
283
|
+
module BCDD::Result::Contract
|
283
284
|
module Interface
|
284
|
-
def ==: (BCDD::Result::
|
285
|
+
def ==: (BCDD::Result::Contract::Interface) -> bool
|
285
286
|
|
286
287
|
def allowed_types: -> Set[Symbol]
|
287
288
|
|
@@ -295,7 +296,7 @@ module BCDD::Result::Expectations::Contract
|
|
295
296
|
end
|
296
297
|
end
|
297
298
|
|
298
|
-
module BCDD::Result::
|
299
|
+
module BCDD::Result::Contract
|
299
300
|
module Disabled
|
300
301
|
extend Interface
|
301
302
|
|
@@ -303,7 +304,7 @@ module BCDD::Result::Expectations::Contract
|
|
303
304
|
end
|
304
305
|
end
|
305
306
|
|
306
|
-
module BCDD::Result::
|
307
|
+
module BCDD::Result::Contract
|
307
308
|
class ForTypes
|
308
309
|
include Interface
|
309
310
|
|
@@ -311,29 +312,280 @@ module BCDD::Result::Expectations::Contract
|
|
311
312
|
end
|
312
313
|
end
|
313
314
|
|
314
|
-
module BCDD::Result::
|
315
|
+
module BCDD::Result::Contract
|
315
316
|
class ForTypesAndValues
|
316
317
|
include Interface
|
317
318
|
|
318
|
-
def initialize: (
|
319
|
+
def initialize: (
|
320
|
+
Hash[Symbol, untyped],
|
321
|
+
Hash[Symbol, Hash[Symbol, bool]]
|
322
|
+
) -> void
|
323
|
+
|
324
|
+
private
|
325
|
+
|
326
|
+
def nil_as_valid_value_checking?: -> bool
|
319
327
|
end
|
320
328
|
end
|
321
329
|
|
322
|
-
module BCDD::Result::
|
330
|
+
module BCDD::Result::Contract
|
323
331
|
class Evaluator
|
324
332
|
include Interface
|
325
333
|
|
326
334
|
attr_reader allowed_types: Set[Symbol]
|
327
|
-
attr_reader success: BCDD::Result::
|
328
|
-
attr_reader failure: BCDD::Result::
|
335
|
+
attr_reader success: BCDD::Result::Contract::Interface
|
336
|
+
attr_reader failure: BCDD::Result::Contract::Interface
|
329
337
|
|
330
338
|
def initialize: (
|
331
|
-
BCDD::Result::
|
332
|
-
BCDD::Result::
|
339
|
+
BCDD::Result::Contract::Interface,
|
340
|
+
BCDD::Result::Contract::Interface
|
333
341
|
) -> void
|
334
342
|
|
335
343
|
private
|
336
344
|
|
337
|
-
def for: (BCDD::Result::Data) -> BCDD::Result::
|
345
|
+
def for: (BCDD::Result::Data) -> BCDD::Result::Contract::Interface
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
class BCDD::Result::Expectations
|
350
|
+
def self.mixin: (
|
351
|
+
?config: Hash[Symbol, Hash[Symbol, bool]],
|
352
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
353
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
354
|
+
) -> Module
|
355
|
+
|
356
|
+
def self.mixin!: (
|
357
|
+
?config: Hash[Symbol, Hash[Symbol, bool]],
|
358
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
359
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
360
|
+
) -> Module
|
361
|
+
|
362
|
+
def self.mixin_module: -> singleton(BCDD::Result::Expectations::Mixin)
|
363
|
+
|
364
|
+
def self.result_factory_without_expectations: -> singleton(BCDD::Result)
|
365
|
+
|
366
|
+
def self.new: (
|
367
|
+
?subject: untyped,
|
368
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
369
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
370
|
+
?contract: BCDD::Result::Contract::Evaluator,
|
371
|
+
?config: Hash[Symbol, Hash[Symbol, bool]]
|
372
|
+
) -> (BCDD::Result::Expectations | untyped)
|
373
|
+
|
374
|
+
def initialize: (
|
375
|
+
?subject: untyped,
|
376
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
377
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
378
|
+
?contract: BCDD::Result::Contract::Evaluator,
|
379
|
+
?config: Hash[Symbol, Hash[Symbol, bool]]
|
380
|
+
) -> void
|
381
|
+
|
382
|
+
def Success: (Symbol, ?untyped) -> BCDD::Result::Success
|
383
|
+
def Failure: (Symbol, ?untyped) -> BCDD::Result::Failure
|
384
|
+
|
385
|
+
def with: (subject: untyped) -> BCDD::Result::Expectations
|
386
|
+
|
387
|
+
private
|
388
|
+
|
389
|
+
attr_reader subject: untyped
|
390
|
+
attr_reader contract: BCDD::Result::Contract::Evaluator
|
391
|
+
end
|
392
|
+
|
393
|
+
module BCDD::Result::Expectations::Mixin
|
394
|
+
module Factory
|
395
|
+
def self.module!: -> Module
|
338
396
|
end
|
397
|
+
|
398
|
+
METHODS: String
|
399
|
+
|
400
|
+
module Addons
|
401
|
+
module Continuable
|
402
|
+
private def Continue: (untyped) -> BCDD::Result::Success
|
403
|
+
end
|
404
|
+
|
405
|
+
OPTIONS: Hash[Symbol, Module]
|
406
|
+
|
407
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
class BCDD::Result::Context < BCDD::Result
|
412
|
+
EXPECTED_OUTCOME: String
|
413
|
+
|
414
|
+
SubjectMethodArity: ^(Method) -> Integer
|
415
|
+
|
416
|
+
attr_reader acc: Hash[Symbol, untyped]
|
417
|
+
|
418
|
+
def initialize: (
|
419
|
+
type: Symbol,
|
420
|
+
value: untyped,
|
421
|
+
?subject: untyped,
|
422
|
+
?expectations: BCDD::Result::Contract::Evaluator
|
423
|
+
) -> void
|
424
|
+
|
425
|
+
def and_then: (?Symbol, **untyped) ?{ (Hash[Symbol, untyped]) -> untyped } -> BCDD::Result::Context
|
426
|
+
|
427
|
+
private
|
428
|
+
|
429
|
+
def call_subject_method: (Symbol, Hash[Symbol, untyped]) -> BCDD::Result::Context
|
430
|
+
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result::Context
|
431
|
+
|
432
|
+
def raise_unexpected_outcome_error: (BCDD::Result::Context | untyped, Symbol) -> void
|
433
|
+
end
|
434
|
+
|
435
|
+
class BCDD::Result::Context
|
436
|
+
class Success < BCDD::Result::Context
|
437
|
+
include BCDD::Result::Success::Methods
|
438
|
+
|
439
|
+
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Success
|
440
|
+
end
|
441
|
+
|
442
|
+
def self.Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
443
|
+
end
|
444
|
+
|
445
|
+
class BCDD::Result::Context
|
446
|
+
class Failure < BCDD::Result::Context
|
447
|
+
include BCDD::Result::Failure::Methods
|
448
|
+
|
449
|
+
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Failure
|
450
|
+
end
|
451
|
+
|
452
|
+
def self.Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
453
|
+
end
|
454
|
+
|
455
|
+
class BCDD::Result::Context
|
456
|
+
module Mixin
|
457
|
+
Factory: singleton(BCDD::Result::Mixin::Factory)
|
458
|
+
|
459
|
+
module Methods
|
460
|
+
def Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
461
|
+
|
462
|
+
def Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
463
|
+
end
|
464
|
+
|
465
|
+
module Addons
|
466
|
+
module Continuable
|
467
|
+
include BCDD::Result::Context::Mixin::Methods
|
468
|
+
|
469
|
+
private
|
470
|
+
|
471
|
+
def Continue: (**untyped) -> BCDD::Result::Context::Success
|
472
|
+
end
|
473
|
+
|
474
|
+
OPTIONS: Hash[Symbol, Module]
|
475
|
+
|
476
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
def self.mixin_module: -> singleton(BCDD::Result::Context::Mixin)
|
481
|
+
|
482
|
+
def self.result_factory: -> singleton(BCDD::Result::Context)
|
483
|
+
end
|
484
|
+
|
485
|
+
class BCDD::Result::Context::Expectations < BCDD::Result::Expectations
|
486
|
+
def self.mixin_module: -> singleton(BCDD::Result::Context::Expectations::Mixin)
|
487
|
+
|
488
|
+
def self.result_factory_without_expectations: -> singleton(BCDD::Result)
|
489
|
+
|
490
|
+
def Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
491
|
+
def Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
492
|
+
end
|
493
|
+
|
494
|
+
module BCDD::Result::Context::Expectations::Mixin
|
495
|
+
METHODS: String
|
496
|
+
Factory: singleton(BCDD::Result::Expectations::Mixin::Factory)
|
497
|
+
|
498
|
+
module Addons
|
499
|
+
module Continuable
|
500
|
+
private def Continue: (**untyped) -> BCDD::Result::Context::Success
|
501
|
+
end
|
502
|
+
|
503
|
+
OPTIONS: Hash[Symbol, Module]
|
504
|
+
|
505
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
class BCDD::Result::Config
|
510
|
+
include Singleton
|
511
|
+
|
512
|
+
ADDON: Hash[Symbol, Hash[Symbol, untyped]]
|
513
|
+
FEATURE: Hash[Symbol, Hash[Symbol, untyped]]
|
514
|
+
PATTERN_MATCHING: Hash[Symbol, Hash[Symbol, untyped]]
|
515
|
+
|
516
|
+
attr_reader addon: BCDD::Result::Config::Switcher
|
517
|
+
attr_reader feature: BCDD::Result::Config::Switcher
|
518
|
+
attr_reader constant_alias: BCDD::Result::Config::Switcher
|
519
|
+
attr_reader pattern_matching: BCDD::Result::Config::Switcher
|
520
|
+
|
521
|
+
def self.instance: -> BCDD::Result::Config
|
522
|
+
|
523
|
+
def initialize: -> void
|
524
|
+
|
525
|
+
def freeze: -> BCDD::Result::Config
|
526
|
+
def options: -> Hash[Symbol, BCDD::Result::Config::Switcher]
|
527
|
+
def to_h: -> Hash[Symbol, Hash[Symbol | String, bool]]
|
528
|
+
end
|
529
|
+
|
530
|
+
class BCDD::Result::Config::Switcher
|
531
|
+
private attr_reader _affects: Hash[Symbol | String, Array[String]]
|
532
|
+
private attr_reader _options: Hash[Symbol | String, bool]
|
533
|
+
private attr_reader listener: Proc
|
534
|
+
|
535
|
+
def initialize: (
|
536
|
+
options: Hash[Symbol | String, Hash[Symbol, untyped]],
|
537
|
+
?listener: Proc
|
538
|
+
) -> void
|
539
|
+
|
540
|
+
def freeze: -> BCDD::Result::Config::Switcher
|
541
|
+
|
542
|
+
def to_h: -> Hash[Symbol | String, bool]
|
543
|
+
|
544
|
+
def options: -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
545
|
+
|
546
|
+
def enabled?: (Symbol | String) -> bool
|
547
|
+
|
548
|
+
def enable!: (*(Symbol | String)) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
549
|
+
|
550
|
+
def disable!: (*(Symbol | String)) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
551
|
+
|
552
|
+
private
|
553
|
+
|
554
|
+
def set_many: (Array[Symbol | String], to: bool) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
555
|
+
|
556
|
+
def set_one: (Symbol | String, bool) -> void
|
557
|
+
|
558
|
+
def require_option!: (Array[Symbol | String]) -> void
|
559
|
+
|
560
|
+
def validate_option!: (Symbol | String) -> void
|
561
|
+
|
562
|
+
def available_options_message: -> String
|
563
|
+
end
|
564
|
+
|
565
|
+
module BCDD::Result::Config::ConstantAlias
|
566
|
+
RESULT: String
|
567
|
+
|
568
|
+
OPTIONS: Hash[String, Hash[Symbol, untyped]]
|
569
|
+
MAPPING: Hash[String, Hash[Symbol, untyped]]
|
570
|
+
Listener: Proc
|
571
|
+
|
572
|
+
def self.switcher: -> BCDD::Result::Config::Switcher
|
573
|
+
end
|
574
|
+
|
575
|
+
module BCDD::Result::Config::Options
|
576
|
+
def self.with_defaults: (
|
577
|
+
Hash[Symbol, Hash[Symbol, bool]],
|
578
|
+
Symbol
|
579
|
+
) -> Hash[Symbol, bool]
|
580
|
+
|
581
|
+
def self.filter_map: (
|
582
|
+
Hash[Symbol, Hash[Symbol, bool]],
|
583
|
+
config: Symbol,
|
584
|
+
from: Hash[Symbol, untyped]
|
585
|
+
) -> Array[untyped]
|
586
|
+
|
587
|
+
def self.addon: (
|
588
|
+
map: Hash[Symbol, Hash[Symbol, bool]],
|
589
|
+
from: Hash[Symbol, Module]
|
590
|
+
) -> Array[Module]
|
339
591
|
end
|
metadata
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcdd-result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
It's a general-purpose result monad that allows you to create objects representing a success (BCDD::Result::Success) or failure (BCDD::Result::Failure).
|
13
|
+
description: Empower Ruby apps with pragmatic use of Result monad, Railway Oriented
|
14
|
+
Programming, and B/CDD.
|
17
15
|
email:
|
18
16
|
- rodrigo.serradura@gmail.com
|
19
17
|
executables: []
|
@@ -28,26 +26,38 @@ files:
|
|
28
26
|
- README.md
|
29
27
|
- Rakefile
|
30
28
|
- Steepfile
|
29
|
+
- lib/bcdd-result.rb
|
31
30
|
- lib/bcdd/result.rb
|
31
|
+
- lib/bcdd/result/config.rb
|
32
|
+
- lib/bcdd/result/config/constant_alias.rb
|
33
|
+
- lib/bcdd/result/config/options.rb
|
34
|
+
- lib/bcdd/result/config/switcher.rb
|
35
|
+
- lib/bcdd/result/context.rb
|
36
|
+
- lib/bcdd/result/context/expectations.rb
|
37
|
+
- lib/bcdd/result/context/expectations/mixin.rb
|
38
|
+
- lib/bcdd/result/context/failure.rb
|
39
|
+
- lib/bcdd/result/context/mixin.rb
|
40
|
+
- lib/bcdd/result/context/success.rb
|
41
|
+
- lib/bcdd/result/contract.rb
|
42
|
+
- lib/bcdd/result/contract/disabled.rb
|
43
|
+
- lib/bcdd/result/contract/error.rb
|
44
|
+
- lib/bcdd/result/contract/evaluator.rb
|
45
|
+
- lib/bcdd/result/contract/for_types.rb
|
46
|
+
- lib/bcdd/result/contract/for_types_and_values.rb
|
47
|
+
- lib/bcdd/result/contract/interface.rb
|
48
|
+
- lib/bcdd/result/contract/type_checker.rb
|
32
49
|
- lib/bcdd/result/data.rb
|
33
50
|
- lib/bcdd/result/error.rb
|
34
51
|
- 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
52
|
- lib/bcdd/result/expectations/mixin.rb
|
43
|
-
- lib/bcdd/result/expectations/type_checker.rb
|
44
53
|
- lib/bcdd/result/failure.rb
|
54
|
+
- lib/bcdd/result/failure/methods.rb
|
45
55
|
- lib/bcdd/result/handler.rb
|
46
56
|
- lib/bcdd/result/handler/allowed_types.rb
|
47
57
|
- lib/bcdd/result/mixin.rb
|
48
58
|
- lib/bcdd/result/success.rb
|
59
|
+
- lib/bcdd/result/success/methods.rb
|
49
60
|
- lib/bcdd/result/version.rb
|
50
|
-
- lib/result.rb
|
51
61
|
- sig/bcdd/result.rbs
|
52
62
|
homepage: https://github.com/b-cdd/result
|
53
63
|
licenses:
|
@@ -76,5 +86,6 @@ requirements: []
|
|
76
86
|
rubygems_version: 3.4.19
|
77
87
|
signing_key:
|
78
88
|
specification_version: 4
|
79
|
-
summary:
|
89
|
+
summary: Empower Ruby apps with pragmatic use of Result monad, Railway Oriented Programming,
|
90
|
+
and B/CDD.
|
80
91
|
test_files: []
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class BCDD::Result::Expectations
|
4
|
-
class Contract::ForTypesAndValues
|
5
|
-
include Contract::Interface
|
6
|
-
|
7
|
-
def initialize(types_and_values)
|
8
|
-
@types_and_values = types_and_values.transform_keys(&:to_sym)
|
9
|
-
|
10
|
-
@types_contract = Contract::ForTypes.new(@types_and_values.keys)
|
11
|
-
end
|
12
|
-
|
13
|
-
def allowed_types
|
14
|
-
@types_contract.allowed_types
|
15
|
-
end
|
16
|
-
|
17
|
-
def type?(type)
|
18
|
-
@types_contract.type?(type)
|
19
|
-
end
|
20
|
-
|
21
|
-
def type!(type)
|
22
|
-
@types_contract.type!(type)
|
23
|
-
end
|
24
|
-
|
25
|
-
def type_and_value!(data)
|
26
|
-
type = data.type
|
27
|
-
value = data.value
|
28
|
-
allowed_value = @types_and_values[type!(type)]
|
29
|
-
|
30
|
-
return value if allowed_value === value
|
31
|
-
|
32
|
-
raise Error::UnexpectedValue.build(type: type, value: value)
|
33
|
-
rescue NoMatchingPatternError
|
34
|
-
raise Error::UnexpectedValue.build(type: data.type, value: data.value)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|