bcdd-result 0.6.0 → 0.7.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 +24 -11
- data/CHANGELOG.md +28 -0
- data/README.md +585 -160
- data/lib/bcdd/result/context/expectations/mixin.rb +35 -0
- data/lib/bcdd/result/context/expectations.rb +41 -0
- data/lib/bcdd/result/context/failure.rb +9 -0
- data/lib/bcdd/result/context/mixin.rb +38 -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/{expectations/contract → contract}/for_types_and_values.rb +10 -8
- 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 +43 -0
- data/lib/bcdd/result/error.rb +7 -9
- data/lib/bcdd/result/expectations/mixin.rb +14 -9
- data/lib/bcdd/result/expectations.rb +28 -37
- data/lib/bcdd/result/failure/methods.rb +21 -0
- data/lib/bcdd/result/failure.rb +2 -16
- data/lib/bcdd/result/mixin.rb +8 -3
- 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 +6 -4
- data/sig/bcdd/result.rbs +227 -83
- metadata +18 -10
- data/lib/bcdd/result/expectations/contract/interface.rb +0 -21
- data/lib/bcdd/result/expectations/contract.rb +0 -25
data/lib/bcdd/result/version.rb
CHANGED
data/lib/bcdd/result.rb
CHANGED
@@ -7,7 +7,9 @@ require_relative 'result/handler'
|
|
7
7
|
require_relative 'result/failure'
|
8
8
|
require_relative 'result/success'
|
9
9
|
require_relative 'result/mixin'
|
10
|
+
require_relative 'result/contract'
|
10
11
|
require_relative 'result/expectations'
|
12
|
+
require_relative 'result/context'
|
11
13
|
|
12
14
|
class BCDD::Result
|
13
15
|
attr_accessor :unknown
|
@@ -21,7 +23,7 @@ class BCDD::Result
|
|
21
23
|
def initialize(type:, value:, subject: nil, expectations: nil)
|
22
24
|
data = Data.new(name, type, value)
|
23
25
|
|
24
|
-
@type_checker =
|
26
|
+
@type_checker = Contract.evaluate(data, expectations)
|
25
27
|
@subject = subject
|
26
28
|
@data = data
|
27
29
|
|
@@ -69,7 +71,7 @@ class BCDD::Result
|
|
69
71
|
def and_then(method_name = nil, context = nil)
|
70
72
|
return self if failure?
|
71
73
|
|
72
|
-
method_name && block_given? and raise ArgumentError, 'method_name and block are mutually exclusive'
|
74
|
+
method_name && block_given? and raise ::ArgumentError, 'method_name and block are mutually exclusive'
|
73
75
|
|
74
76
|
return call_subject_method(method_name, context) if method_name
|
75
77
|
|
@@ -129,7 +131,7 @@ class BCDD::Result
|
|
129
131
|
when 0 then subject.send(method_name)
|
130
132
|
when 1 then subject.send(method_name, value)
|
131
133
|
when 2 then subject.send(method_name, value, context)
|
132
|
-
else raise Error::
|
134
|
+
else raise Error::InvalidSubjectMethodArity.build(subject: subject, method: method, max_arity: 2)
|
133
135
|
end
|
134
136
|
|
135
137
|
ensure_result_object(result, origin: :method)
|
@@ -140,6 +142,6 @@ class BCDD::Result
|
|
140
142
|
|
141
143
|
return result if result.subject.equal?(subject)
|
142
144
|
|
143
|
-
raise Error::
|
145
|
+
raise Error::InvalidResultSubject.build(given_result: result, expected_subject: subject)
|
144
146
|
end
|
145
147
|
end
|
data/sig/bcdd/result.rbs
CHANGED
@@ -6,7 +6,7 @@ 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
|
@@ -15,7 +15,7 @@ class BCDD::Result
|
|
15
15
|
type: Symbol,
|
16
16
|
value: untyped,
|
17
17
|
?subject: untyped,
|
18
|
-
?expectations: BCDD::Result::
|
18
|
+
?expectations: BCDD::Result::Contract::Evaluator
|
19
19
|
) -> void
|
20
20
|
|
21
21
|
def type: -> Symbol
|
@@ -31,7 +31,7 @@ class BCDD::Result
|
|
31
31
|
def on_failure: (*Symbol) { (untyped, Symbol) -> void } -> BCDD::Result
|
32
32
|
def on_unknown: () { (untyped, Symbol) -> void } -> BCDD::Result
|
33
33
|
|
34
|
-
def and_then: (?Symbol method_name, ?untyped context) ?{ (untyped) -> untyped } ->
|
34
|
+
def and_then: (?Symbol method_name, ?untyped context) ?{ (untyped) -> untyped } -> untyped
|
35
35
|
|
36
36
|
def handle: () { (BCDD::Result::Handler) -> void } -> untyped
|
37
37
|
|
@@ -54,17 +54,42 @@ class BCDD::Result
|
|
54
54
|
end
|
55
55
|
|
56
56
|
class BCDD::Result
|
57
|
-
class
|
57
|
+
class Success < BCDD::Result
|
58
|
+
module Methods
|
59
|
+
def success?: (?Symbol type) -> bool
|
60
|
+
def failure?: (?Symbol type) -> bool
|
61
|
+
def value_or: { () -> untyped } -> untyped
|
62
|
+
def value: -> untyped
|
63
|
+
|
64
|
+
private
|
65
|
+
def name: -> Symbol
|
66
|
+
def type_checker: -> BCDD::Result::Contract::TypeChecker
|
67
|
+
end
|
68
|
+
|
69
|
+
include Methods
|
58
70
|
end
|
59
71
|
|
60
|
-
def self.
|
72
|
+
def self.Failure: (Symbol type, ?untyped value) -> BCDD::Result::Failure
|
61
73
|
end
|
62
74
|
|
75
|
+
|
63
76
|
class BCDD::Result
|
64
|
-
class
|
77
|
+
class Failure < BCDD::Result
|
78
|
+
module Methods
|
79
|
+
def success?: (?Symbol type) -> bool
|
80
|
+
def failure?: (?Symbol type) -> bool
|
81
|
+
def value_or: { (untyped) -> untyped } -> untyped
|
82
|
+
def value: -> untyped
|
83
|
+
|
84
|
+
private
|
85
|
+
def name: -> Symbol
|
86
|
+
def type_checker: -> BCDD::Result::Contract::TypeChecker
|
87
|
+
end
|
88
|
+
|
89
|
+
include Methods
|
65
90
|
end
|
66
91
|
|
67
|
-
def self.
|
92
|
+
def self.Success: (Symbol type, ?untyped value) -> BCDD::Result::Success
|
68
93
|
end
|
69
94
|
|
70
95
|
class BCDD::Result
|
@@ -79,13 +104,17 @@ class BCDD::Result
|
|
79
104
|
module Continuable
|
80
105
|
include BCDD::Result::Mixin::Methods
|
81
106
|
|
82
|
-
private
|
107
|
+
private
|
108
|
+
|
109
|
+
def Continue: (untyped) -> BCDD::Result::Success
|
83
110
|
end
|
84
111
|
|
85
112
|
OPTIONS: Hash[Symbol, Module]
|
86
113
|
|
87
114
|
def self.options: (Array[Symbol]) -> Array[Module]
|
88
115
|
end
|
116
|
+
|
117
|
+
def self.module!: -> Module
|
89
118
|
end
|
90
119
|
|
91
120
|
def self.mixin: (?with: Array[Symbol]) -> Module
|
@@ -109,7 +138,7 @@ class BCDD::Result
|
|
109
138
|
end
|
110
139
|
|
111
140
|
class BCDD::Result
|
112
|
-
class Error <
|
141
|
+
class Error < StandardError
|
113
142
|
def self.build: (**untyped) -> BCDD::Result::Error
|
114
143
|
|
115
144
|
class NotImplemented < BCDD::Result::Error
|
@@ -119,18 +148,18 @@ class BCDD::Result
|
|
119
148
|
end
|
120
149
|
|
121
150
|
class UnexpectedOutcome < BCDD::Result::Error
|
122
|
-
def self.build: (outcome: untyped, origin: Symbol)
|
151
|
+
def self.build: (outcome: untyped, origin: Symbol, ?expected: String)
|
123
152
|
-> BCDD::Result::Error::UnexpectedOutcome
|
124
153
|
end
|
125
154
|
|
126
|
-
class
|
155
|
+
class InvalidResultSubject < BCDD::Result::Error
|
127
156
|
def self.build: (given_result: BCDD::Result, expected_subject: untyped)
|
128
|
-
-> BCDD::Result::Error::
|
157
|
+
-> BCDD::Result::Error::InvalidResultSubject
|
129
158
|
end
|
130
159
|
|
131
|
-
class
|
132
|
-
def self.build: (subject: untyped, method:
|
133
|
-
-> BCDD::Result::Error::
|
160
|
+
class InvalidSubjectMethodArity < BCDD::Result::Error
|
161
|
+
def self.build: (subject: untyped, method: Method, max_arity: Integer)
|
162
|
+
-> BCDD::Result::Error::InvalidSubjectMethodArity
|
134
163
|
end
|
135
164
|
|
136
165
|
class UnhandledTypes < BCDD::Result::Error
|
@@ -146,7 +175,7 @@ class BCDD::Result
|
|
146
175
|
|
147
176
|
def initialize: (
|
148
177
|
BCDD::Result,
|
149
|
-
type_checker: BCDD::Result::
|
178
|
+
type_checker: BCDD::Result::Contract::TypeChecker
|
150
179
|
) -> void
|
151
180
|
|
152
181
|
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
@@ -170,10 +199,10 @@ end
|
|
170
199
|
class BCDD::Result::Handler
|
171
200
|
class AllowedTypes
|
172
201
|
attr_reader unchecked: Set[Symbol]
|
173
|
-
attr_reader type_checker: BCDD::Result::
|
202
|
+
attr_reader type_checker: BCDD::Result::Contract::TypeChecker
|
174
203
|
|
175
204
|
def initialize: (
|
176
|
-
BCDD::Result::
|
205
|
+
BCDD::Result::Contract::TypeChecker
|
177
206
|
) -> void
|
178
207
|
|
179
208
|
def allow?: (Array[Symbol]) -> bool
|
@@ -188,69 +217,34 @@ class BCDD::Result::Handler
|
|
188
217
|
end
|
189
218
|
end
|
190
219
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
def self.mixin: (
|
195
|
-
?success: Hash[Symbol, untyped] | Array[Symbol],
|
196
|
-
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
197
|
-
) -> Module
|
220
|
+
module BCDD::Result::Contract
|
221
|
+
NONE: BCDD::Result::Contract::Evaluator
|
198
222
|
|
199
223
|
def self.evaluate: (
|
200
224
|
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
|
233
|
-
|
234
|
-
module BCDD::Result::Expectations::Contract
|
235
|
-
NONE: BCDD::Result::Expectations::Contract::Evaluator
|
225
|
+
BCDD::Result::Contract::Evaluator
|
226
|
+
) -> BCDD::Result::Contract::TypeChecker
|
236
227
|
|
237
228
|
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol])
|
238
|
-
-> BCDD::Result::
|
229
|
+
-> BCDD::Result::Contract::Evaluator
|
239
230
|
|
240
231
|
def self.new: (
|
241
232
|
success: Hash[Symbol, untyped] | Array[Symbol],
|
242
233
|
failure: Hash[Symbol, untyped] | Array[Symbol]
|
243
|
-
) -> BCDD::Result::
|
234
|
+
) -> BCDD::Result::Contract::Evaluator
|
235
|
+
|
236
|
+
def self.nil_as_valid_value_checking!: (?enabled: bool) -> void
|
237
|
+
def self.nil_as_valid_value_checking?: -> bool
|
244
238
|
end
|
245
239
|
|
246
|
-
|
240
|
+
module BCDD::Result::Contract
|
247
241
|
class TypeChecker
|
248
242
|
attr_reader result_type: Symbol
|
249
|
-
attr_reader expectations: BCDD::Result::
|
243
|
+
attr_reader expectations: BCDD::Result::Contract::Evaluator
|
250
244
|
|
251
245
|
def initialize: (
|
252
246
|
Symbol,
|
253
|
-
expectations: BCDD::Result::
|
247
|
+
expectations: BCDD::Result::Contract::Evaluator
|
254
248
|
) -> void
|
255
249
|
|
256
250
|
def allow?: (Array[Symbol]) -> bool
|
@@ -261,27 +255,27 @@ class BCDD::Result::Expectations
|
|
261
255
|
|
262
256
|
def validate: (
|
263
257
|
Array[Symbol],
|
264
|
-
expected: BCDD::Result::
|
258
|
+
expected: BCDD::Result::Contract::Interface,
|
265
259
|
allow_empty: bool
|
266
260
|
) -> bool
|
267
261
|
end
|
268
262
|
end
|
269
263
|
|
270
|
-
class BCDD::Result::
|
271
|
-
class UnexpectedType < BCDD::Result::
|
264
|
+
class BCDD::Result::Contract::Error < BCDD::Result::Error
|
265
|
+
class UnexpectedType < BCDD::Result::Contract::Error
|
272
266
|
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
273
|
-
-> BCDD::Result::
|
267
|
+
-> BCDD::Result::Contract::Error::UnexpectedType
|
274
268
|
end
|
275
269
|
|
276
|
-
class UnexpectedValue < BCDD::Result::
|
277
|
-
def self.build: (type: Symbol, value: untyped)
|
278
|
-
-> BCDD::Result::
|
270
|
+
class UnexpectedValue < BCDD::Result::Contract::Error
|
271
|
+
def self.build: (type: Symbol, value: untyped, ?cause: Exception)
|
272
|
+
-> BCDD::Result::Contract::Error::UnexpectedValue
|
279
273
|
end
|
280
274
|
end
|
281
275
|
|
282
|
-
module BCDD::Result::
|
276
|
+
module BCDD::Result::Contract
|
283
277
|
module Interface
|
284
|
-
def ==: (BCDD::Result::
|
278
|
+
def ==: (BCDD::Result::Contract::Interface) -> bool
|
285
279
|
|
286
280
|
def allowed_types: -> Set[Symbol]
|
287
281
|
|
@@ -295,7 +289,7 @@ module BCDD::Result::Expectations::Contract
|
|
295
289
|
end
|
296
290
|
end
|
297
291
|
|
298
|
-
module BCDD::Result::
|
292
|
+
module BCDD::Result::Contract
|
299
293
|
module Disabled
|
300
294
|
extend Interface
|
301
295
|
|
@@ -303,7 +297,7 @@ module BCDD::Result::Expectations::Contract
|
|
303
297
|
end
|
304
298
|
end
|
305
299
|
|
306
|
-
module BCDD::Result::
|
300
|
+
module BCDD::Result::Contract
|
307
301
|
class ForTypes
|
308
302
|
include Interface
|
309
303
|
|
@@ -311,7 +305,7 @@ module BCDD::Result::Expectations::Contract
|
|
311
305
|
end
|
312
306
|
end
|
313
307
|
|
314
|
-
module BCDD::Result::
|
308
|
+
module BCDD::Result::Contract
|
315
309
|
class ForTypesAndValues
|
316
310
|
include Interface
|
317
311
|
|
@@ -319,21 +313,171 @@ module BCDD::Result::Expectations::Contract
|
|
319
313
|
end
|
320
314
|
end
|
321
315
|
|
322
|
-
module BCDD::Result::
|
316
|
+
module BCDD::Result::Contract
|
323
317
|
class Evaluator
|
324
318
|
include Interface
|
325
319
|
|
326
320
|
attr_reader allowed_types: Set[Symbol]
|
327
|
-
attr_reader success: BCDD::Result::
|
328
|
-
attr_reader failure: BCDD::Result::
|
321
|
+
attr_reader success: BCDD::Result::Contract::Interface
|
322
|
+
attr_reader failure: BCDD::Result::Contract::Interface
|
329
323
|
|
330
324
|
def initialize: (
|
331
|
-
BCDD::Result::
|
332
|
-
BCDD::Result::
|
325
|
+
BCDD::Result::Contract::Interface,
|
326
|
+
BCDD::Result::Contract::Interface
|
333
327
|
) -> void
|
334
328
|
|
335
329
|
private
|
336
330
|
|
337
|
-
def for: (BCDD::Result::Data) -> BCDD::Result::
|
331
|
+
def for: (BCDD::Result::Data) -> BCDD::Result::Contract::Interface
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class BCDD::Result::Expectations
|
336
|
+
def self.mixin: (
|
337
|
+
?with: Symbol,
|
338
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
339
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
340
|
+
) -> Module
|
341
|
+
|
342
|
+
def initialize: (
|
343
|
+
?subject: untyped,
|
344
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
345
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
346
|
+
?contract: BCDD::Result::Contract::Evaluator
|
347
|
+
) -> void
|
348
|
+
|
349
|
+
def Success: (Symbol, ?untyped) -> BCDD::Result::Success
|
350
|
+
def Failure: (Symbol, ?untyped) -> BCDD::Result::Failure
|
351
|
+
|
352
|
+
def with: (subject: untyped) -> BCDD::Result::Expectations
|
353
|
+
|
354
|
+
private
|
355
|
+
|
356
|
+
attr_reader subject: untyped
|
357
|
+
attr_reader contract: BCDD::Result::Contract::Evaluator
|
358
|
+
end
|
359
|
+
|
360
|
+
module BCDD::Result::Expectations::Mixin
|
361
|
+
METHODS: String
|
362
|
+
|
363
|
+
module Addons
|
364
|
+
module Continuable
|
365
|
+
private def Continue: (untyped) -> BCDD::Result::Success
|
366
|
+
end
|
367
|
+
|
368
|
+
OPTIONS: Hash[Symbol, Module]
|
369
|
+
|
370
|
+
def self.options: (Symbol) -> Array[Module]
|
371
|
+
end
|
372
|
+
|
373
|
+
def self.module!: -> Module
|
374
|
+
end
|
375
|
+
|
376
|
+
class BCDD::Result::Context < BCDD::Result
|
377
|
+
EXPECTED_OUTCOME: String
|
378
|
+
|
379
|
+
SubjectMethodArity: ^(Method) -> Integer
|
380
|
+
|
381
|
+
attr_reader acc: Hash[Symbol, untyped]
|
382
|
+
|
383
|
+
def initialize: (
|
384
|
+
type: Symbol,
|
385
|
+
value: untyped,
|
386
|
+
?subject: untyped,
|
387
|
+
?expectations: BCDD::Result::Contract::Evaluator
|
388
|
+
) -> void
|
389
|
+
|
390
|
+
def and_then: (?Symbol, **untyped) ?{ (Hash[Symbol, untyped]) -> untyped } -> BCDD::Result::Context
|
391
|
+
|
392
|
+
private
|
393
|
+
|
394
|
+
def call_subject_method: (Symbol, Hash[Symbol, untyped]) -> BCDD::Result::Context
|
395
|
+
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result::Context
|
396
|
+
|
397
|
+
def raise_unexpected_outcome_error: (BCDD::Result::Context | untyped, Symbol) -> void
|
398
|
+
end
|
399
|
+
|
400
|
+
class BCDD::Result::Context
|
401
|
+
class Success < BCDD::Result::Context
|
402
|
+
include BCDD::Result::Success::Methods
|
403
|
+
|
404
|
+
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Success
|
405
|
+
end
|
406
|
+
|
407
|
+
def self.Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
408
|
+
end
|
409
|
+
|
410
|
+
class BCDD::Result::Context
|
411
|
+
class Failure < BCDD::Result::Context
|
412
|
+
include BCDD::Result::Failure::Methods
|
413
|
+
|
414
|
+
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Failure
|
415
|
+
end
|
416
|
+
|
417
|
+
def self.Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
418
|
+
end
|
419
|
+
|
420
|
+
class BCDD::Result::Context
|
421
|
+
module Mixin
|
422
|
+
module Methods
|
423
|
+
def Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
424
|
+
|
425
|
+
def Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
426
|
+
end
|
427
|
+
|
428
|
+
module Addons
|
429
|
+
module Continuable
|
430
|
+
include BCDD::Result::Context::Mixin::Methods
|
431
|
+
|
432
|
+
private
|
433
|
+
|
434
|
+
def Continue: (**untyped) -> BCDD::Result::Context::Success
|
435
|
+
end
|
436
|
+
|
437
|
+
OPTIONS: Hash[Symbol, Module]
|
438
|
+
|
439
|
+
def self.options: (Array[Symbol]) -> Array[Module]
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
def self.mixin: (?with: Array[Symbol]) -> Module
|
444
|
+
end
|
445
|
+
|
446
|
+
class BCDD::Result::Context::Expectations
|
447
|
+
def self.mixin: (
|
448
|
+
?with: Symbol,
|
449
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
450
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
451
|
+
) -> Module
|
452
|
+
|
453
|
+
def initialize: (
|
454
|
+
?subject: untyped,
|
455
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
456
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
457
|
+
?contract: BCDD::Result::Contract::Evaluator
|
458
|
+
) -> void
|
459
|
+
|
460
|
+
def Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
461
|
+
def Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|
462
|
+
|
463
|
+
def with: (subject: untyped) -> BCDD::Result::Context::Expectations
|
464
|
+
|
465
|
+
private
|
466
|
+
|
467
|
+
attr_reader subject: untyped
|
468
|
+
attr_reader contract: BCDD::Result::Contract::Evaluator
|
469
|
+
end
|
470
|
+
|
471
|
+
module BCDD::Result::Context::Expectations::Mixin
|
472
|
+
METHODS: String
|
473
|
+
|
474
|
+
module Addons
|
475
|
+
module Continuable
|
476
|
+
private def Continue: (**untyped) -> BCDD::Result::Context::Success
|
477
|
+
end
|
478
|
+
|
479
|
+
OPTIONS: Hash[Symbol, Module]
|
480
|
+
|
481
|
+
def self.options: (Symbol) -> Array[Module]
|
338
482
|
end
|
339
483
|
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.7.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-10-
|
11
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Empower Ruby apps with a pragmatic use of Railway Oriented Programming.
|
@@ -29,23 +29,31 @@ files:
|
|
29
29
|
- Rakefile
|
30
30
|
- Steepfile
|
31
31
|
- lib/bcdd/result.rb
|
32
|
+
- lib/bcdd/result/context.rb
|
33
|
+
- lib/bcdd/result/context/expectations.rb
|
34
|
+
- lib/bcdd/result/context/expectations/mixin.rb
|
35
|
+
- lib/bcdd/result/context/failure.rb
|
36
|
+
- lib/bcdd/result/context/mixin.rb
|
37
|
+
- lib/bcdd/result/context/success.rb
|
38
|
+
- lib/bcdd/result/contract.rb
|
39
|
+
- lib/bcdd/result/contract/disabled.rb
|
40
|
+
- lib/bcdd/result/contract/error.rb
|
41
|
+
- lib/bcdd/result/contract/evaluator.rb
|
42
|
+
- lib/bcdd/result/contract/for_types.rb
|
43
|
+
- lib/bcdd/result/contract/for_types_and_values.rb
|
44
|
+
- lib/bcdd/result/contract/interface.rb
|
45
|
+
- lib/bcdd/result/contract/type_checker.rb
|
32
46
|
- lib/bcdd/result/data.rb
|
33
47
|
- lib/bcdd/result/error.rb
|
34
48
|
- 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
49
|
- lib/bcdd/result/expectations/mixin.rb
|
43
|
-
- lib/bcdd/result/expectations/type_checker.rb
|
44
50
|
- lib/bcdd/result/failure.rb
|
51
|
+
- lib/bcdd/result/failure/methods.rb
|
45
52
|
- lib/bcdd/result/handler.rb
|
46
53
|
- lib/bcdd/result/handler/allowed_types.rb
|
47
54
|
- lib/bcdd/result/mixin.rb
|
48
55
|
- lib/bcdd/result/success.rb
|
56
|
+
- lib/bcdd/result/success/methods.rb
|
49
57
|
- lib/bcdd/result/version.rb
|
50
58
|
- lib/result.rb
|
51
59
|
- sig/bcdd/result.rbs
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class BCDD::Result::Expectations
|
4
|
-
module Contract::Interface
|
5
|
-
def allowed_types
|
6
|
-
raise ::BCDD::Result::Error::NotImplemented
|
7
|
-
end
|
8
|
-
|
9
|
-
def type?(_type)
|
10
|
-
raise ::BCDD::Result::Error::NotImplemented
|
11
|
-
end
|
12
|
-
|
13
|
-
def type!(_type)
|
14
|
-
raise ::BCDD::Result::Error::NotImplemented
|
15
|
-
end
|
16
|
-
|
17
|
-
def type_and_value!(_data)
|
18
|
-
raise ::BCDD::Result::Error::NotImplemented
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class BCDD::Result::Expectations
|
4
|
-
module Contract
|
5
|
-
require_relative 'contract/interface'
|
6
|
-
require_relative 'contract/evaluator'
|
7
|
-
require_relative 'contract/disabled'
|
8
|
-
require_relative 'contract/for_types'
|
9
|
-
require_relative 'contract/for_types_and_values'
|
10
|
-
|
11
|
-
NONE = Contract::Evaluator.new(Contract::Disabled, Contract::Disabled).freeze
|
12
|
-
|
13
|
-
ToEnsure = ->(spec) do
|
14
|
-
return Contract::Disabled if spec.nil?
|
15
|
-
|
16
|
-
spec.is_a?(Hash) ? Contract::ForTypesAndValues.new(spec) : Contract::ForTypes.new(Array(spec))
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.new(success:, failure:)
|
20
|
-
Contract::Evaluator.new(ToEnsure[success], ToEnsure[failure])
|
21
|
-
end
|
22
|
-
|
23
|
-
private_constant :ToEnsure
|
24
|
-
end
|
25
|
-
end
|