bcdd-result 0.5.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 +30 -10
- data/CHANGELOG.md +49 -2
- data/README.md +709 -127
- 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 +42 -0
- data/lib/bcdd/result/expectations.rb +27 -48
- data/lib/bcdd/result/failure/methods.rb +21 -0
- data/lib/bcdd/result/failure.rb +2 -16
- data/lib/bcdd/result/mixin.rb +36 -4
- 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 +11 -6
- data/sig/bcdd/result.rbs +245 -71
- metadata +19 -10
- data/lib/bcdd/result/expectations/contract/interface.rb +0 -21
- data/lib/bcdd/result/expectations/contract.rb +0 -25
data/lib/bcdd/result/success.rb
CHANGED
@@ -2,23 +2,9 @@
|
|
2
2
|
|
3
3
|
class BCDD::Result
|
4
4
|
class Success < self
|
5
|
-
|
6
|
-
type.nil? || type_checker.allow_success?([type])
|
7
|
-
end
|
5
|
+
require_relative 'success/methods'
|
8
6
|
|
9
|
-
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def value_or
|
14
|
-
value
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def name
|
20
|
-
:success
|
21
|
-
end
|
7
|
+
include Methods
|
22
8
|
end
|
23
9
|
|
24
10
|
def self.Success(type, value = nil)
|
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
|
|
@@ -66,10 +68,12 @@ class BCDD::Result
|
|
66
68
|
tap { yield(value, type) if unknown }
|
67
69
|
end
|
68
70
|
|
69
|
-
def and_then(method_name = nil)
|
71
|
+
def and_then(method_name = nil, context = nil)
|
70
72
|
return self if failure?
|
71
73
|
|
72
|
-
|
74
|
+
method_name && block_given? and raise ::ArgumentError, 'method_name and block are mutually exclusive'
|
75
|
+
|
76
|
+
return call_subject_method(method_name, context) if method_name
|
73
77
|
|
74
78
|
result = yield(value)
|
75
79
|
|
@@ -119,14 +123,15 @@ class BCDD::Result
|
|
119
123
|
block.call(value, type)
|
120
124
|
end
|
121
125
|
|
122
|
-
def call_subject_method(method_name)
|
126
|
+
def call_subject_method(method_name, context)
|
123
127
|
method = subject.method(method_name)
|
124
128
|
|
125
129
|
result =
|
126
130
|
case method.arity
|
127
131
|
when 0 then subject.send(method_name)
|
128
132
|
when 1 then subject.send(method_name, value)
|
129
|
-
|
133
|
+
when 2 then subject.send(method_name, value, context)
|
134
|
+
else raise Error::InvalidSubjectMethodArity.build(subject: subject, method: method, max_arity: 2)
|
130
135
|
end
|
131
136
|
|
132
137
|
ensure_result_object(result, origin: :method)
|
@@ -137,6 +142,6 @@ class BCDD::Result
|
|
137
142
|
|
138
143
|
return result if result.subject.equal?(subject)
|
139
144
|
|
140
|
-
raise Error::
|
145
|
+
raise Error::InvalidResultSubject.build(given_result: result, expected_subject: subject)
|
141
146
|
end
|
142
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) -> 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
|
|
@@ -49,30 +49,75 @@ class BCDD::Result
|
|
49
49
|
|
50
50
|
def name: -> Symbol
|
51
51
|
def known: (Proc) -> untyped
|
52
|
-
def call_subject_method: (Symbol) -> BCDD::Result
|
52
|
+
def call_subject_method: (Symbol, untyped) -> BCDD::Result
|
53
53
|
def ensure_result_object: (untyped, origin: Symbol) -> 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
|
71
96
|
module Mixin
|
72
|
-
|
97
|
+
module Methods
|
98
|
+
def Success: (Symbol type, ?untyped value) -> BCDD::Result::Success
|
99
|
+
|
100
|
+
def Failure: (Symbol type, ?untyped value) -> BCDD::Result::Failure
|
101
|
+
end
|
102
|
+
|
103
|
+
module Addons
|
104
|
+
module Continuable
|
105
|
+
include BCDD::Result::Mixin::Methods
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def Continue: (untyped) -> BCDD::Result::Success
|
110
|
+
end
|
73
111
|
|
74
|
-
|
112
|
+
OPTIONS: Hash[Symbol, Module]
|
113
|
+
|
114
|
+
def self.options: (Array[Symbol]) -> Array[Module]
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.module!: -> Module
|
75
118
|
end
|
119
|
+
|
120
|
+
def self.mixin: (?with: Array[Symbol]) -> Module
|
76
121
|
end
|
77
122
|
|
78
123
|
class BCDD::Result
|
@@ -93,7 +138,7 @@ class BCDD::Result
|
|
93
138
|
end
|
94
139
|
|
95
140
|
class BCDD::Result
|
96
|
-
class Error <
|
141
|
+
class Error < StandardError
|
97
142
|
def self.build: (**untyped) -> BCDD::Result::Error
|
98
143
|
|
99
144
|
class NotImplemented < BCDD::Result::Error
|
@@ -103,18 +148,18 @@ class BCDD::Result
|
|
103
148
|
end
|
104
149
|
|
105
150
|
class UnexpectedOutcome < BCDD::Result::Error
|
106
|
-
def self.build: (outcome: untyped, origin: Symbol)
|
151
|
+
def self.build: (outcome: untyped, origin: Symbol, ?expected: String)
|
107
152
|
-> BCDD::Result::Error::UnexpectedOutcome
|
108
153
|
end
|
109
154
|
|
110
|
-
class
|
155
|
+
class InvalidResultSubject < BCDD::Result::Error
|
111
156
|
def self.build: (given_result: BCDD::Result, expected_subject: untyped)
|
112
|
-
-> BCDD::Result::Error::
|
157
|
+
-> BCDD::Result::Error::InvalidResultSubject
|
113
158
|
end
|
114
159
|
|
115
|
-
class
|
116
|
-
def self.build: (subject: untyped, method:
|
117
|
-
-> 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
|
118
163
|
end
|
119
164
|
|
120
165
|
class UnhandledTypes < BCDD::Result::Error
|
@@ -130,7 +175,7 @@ class BCDD::Result
|
|
130
175
|
|
131
176
|
def initialize: (
|
132
177
|
BCDD::Result,
|
133
|
-
type_checker: BCDD::Result::
|
178
|
+
type_checker: BCDD::Result::Contract::TypeChecker
|
134
179
|
) -> void
|
135
180
|
|
136
181
|
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
@@ -154,10 +199,10 @@ end
|
|
154
199
|
class BCDD::Result::Handler
|
155
200
|
class AllowedTypes
|
156
201
|
attr_reader unchecked: Set[Symbol]
|
157
|
-
attr_reader type_checker: BCDD::Result::
|
202
|
+
attr_reader type_checker: BCDD::Result::Contract::TypeChecker
|
158
203
|
|
159
204
|
def initialize: (
|
160
|
-
BCDD::Result::
|
205
|
+
BCDD::Result::Contract::TypeChecker
|
161
206
|
) -> void
|
162
207
|
|
163
208
|
def allow?: (Array[Symbol]) -> bool
|
@@ -172,55 +217,34 @@ class BCDD::Result::Handler
|
|
172
217
|
end
|
173
218
|
end
|
174
219
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
def self.mixin: (
|
179
|
-
?success: Hash[Symbol, untyped] | Array[Symbol],
|
180
|
-
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
181
|
-
) -> Module
|
220
|
+
module BCDD::Result::Contract
|
221
|
+
NONE: BCDD::Result::Contract::Evaluator
|
182
222
|
|
183
223
|
def self.evaluate: (
|
184
224
|
BCDD::Result::Data,
|
185
|
-
BCDD::Result::
|
186
|
-
) -> BCDD::Result::
|
187
|
-
|
188
|
-
def initialize: (
|
189
|
-
?subject: untyped,
|
190
|
-
?success: Hash[Symbol, untyped] | Array[Symbol],
|
191
|
-
?failure: Hash[Symbol, untyped] | Array[Symbol],
|
192
|
-
?contract: BCDD::Result::Expectations::Contract::Evaluator
|
193
|
-
) -> void
|
194
|
-
|
195
|
-
def Success: (Symbol, ?untyped) -> BCDD::Result::Success
|
196
|
-
def Failure: (Symbol, ?untyped) -> BCDD::Result::Failure
|
197
|
-
|
198
|
-
private
|
199
|
-
|
200
|
-
attr_reader subject: untyped
|
201
|
-
attr_reader contract: BCDD::Result::Expectations::Contract::Evaluator
|
202
|
-
end
|
203
|
-
|
204
|
-
module BCDD::Result::Expectations::Contract
|
205
|
-
NONE: BCDD::Result::Expectations::Contract::Evaluator
|
225
|
+
BCDD::Result::Contract::Evaluator
|
226
|
+
) -> BCDD::Result::Contract::TypeChecker
|
206
227
|
|
207
228
|
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol])
|
208
|
-
-> BCDD::Result::
|
229
|
+
-> BCDD::Result::Contract::Evaluator
|
209
230
|
|
210
231
|
def self.new: (
|
211
232
|
success: Hash[Symbol, untyped] | Array[Symbol],
|
212
233
|
failure: Hash[Symbol, untyped] | Array[Symbol]
|
213
|
-
) -> 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
|
214
238
|
end
|
215
239
|
|
216
|
-
|
240
|
+
module BCDD::Result::Contract
|
217
241
|
class TypeChecker
|
218
242
|
attr_reader result_type: Symbol
|
219
|
-
attr_reader expectations: BCDD::Result::
|
243
|
+
attr_reader expectations: BCDD::Result::Contract::Evaluator
|
220
244
|
|
221
245
|
def initialize: (
|
222
246
|
Symbol,
|
223
|
-
expectations: BCDD::Result::
|
247
|
+
expectations: BCDD::Result::Contract::Evaluator
|
224
248
|
) -> void
|
225
249
|
|
226
250
|
def allow?: (Array[Symbol]) -> bool
|
@@ -231,27 +255,27 @@ class BCDD::Result::Expectations
|
|
231
255
|
|
232
256
|
def validate: (
|
233
257
|
Array[Symbol],
|
234
|
-
expected: BCDD::Result::
|
258
|
+
expected: BCDD::Result::Contract::Interface,
|
235
259
|
allow_empty: bool
|
236
260
|
) -> bool
|
237
261
|
end
|
238
262
|
end
|
239
263
|
|
240
|
-
class BCDD::Result::
|
241
|
-
class UnexpectedType < BCDD::Result::
|
264
|
+
class BCDD::Result::Contract::Error < BCDD::Result::Error
|
265
|
+
class UnexpectedType < BCDD::Result::Contract::Error
|
242
266
|
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
243
|
-
-> BCDD::Result::
|
267
|
+
-> BCDD::Result::Contract::Error::UnexpectedType
|
244
268
|
end
|
245
269
|
|
246
|
-
class UnexpectedValue < BCDD::Result::
|
247
|
-
def self.build: (type: Symbol, value: untyped)
|
248
|
-
-> 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
|
249
273
|
end
|
250
274
|
end
|
251
275
|
|
252
|
-
module BCDD::Result::
|
276
|
+
module BCDD::Result::Contract
|
253
277
|
module Interface
|
254
|
-
def ==: (BCDD::Result::
|
278
|
+
def ==: (BCDD::Result::Contract::Interface) -> bool
|
255
279
|
|
256
280
|
def allowed_types: -> Set[Symbol]
|
257
281
|
|
@@ -265,7 +289,7 @@ module BCDD::Result::Expectations::Contract
|
|
265
289
|
end
|
266
290
|
end
|
267
291
|
|
268
|
-
module BCDD::Result::
|
292
|
+
module BCDD::Result::Contract
|
269
293
|
module Disabled
|
270
294
|
extend Interface
|
271
295
|
|
@@ -273,7 +297,7 @@ module BCDD::Result::Expectations::Contract
|
|
273
297
|
end
|
274
298
|
end
|
275
299
|
|
276
|
-
module BCDD::Result::
|
300
|
+
module BCDD::Result::Contract
|
277
301
|
class ForTypes
|
278
302
|
include Interface
|
279
303
|
|
@@ -281,7 +305,7 @@ module BCDD::Result::Expectations::Contract
|
|
281
305
|
end
|
282
306
|
end
|
283
307
|
|
284
|
-
module BCDD::Result::
|
308
|
+
module BCDD::Result::Contract
|
285
309
|
class ForTypesAndValues
|
286
310
|
include Interface
|
287
311
|
|
@@ -289,21 +313,171 @@ module BCDD::Result::Expectations::Contract
|
|
289
313
|
end
|
290
314
|
end
|
291
315
|
|
292
|
-
module BCDD::Result::
|
316
|
+
module BCDD::Result::Contract
|
293
317
|
class Evaluator
|
294
318
|
include Interface
|
295
319
|
|
296
320
|
attr_reader allowed_types: Set[Symbol]
|
297
|
-
attr_reader success: BCDD::Result::
|
298
|
-
attr_reader failure: BCDD::Result::
|
321
|
+
attr_reader success: BCDD::Result::Contract::Interface
|
322
|
+
attr_reader failure: BCDD::Result::Contract::Interface
|
299
323
|
|
300
324
|
def initialize: (
|
301
|
-
BCDD::Result::
|
302
|
-
BCDD::Result::
|
325
|
+
BCDD::Result::Contract::Interface,
|
326
|
+
BCDD::Result::Contract::Interface
|
303
327
|
) -> void
|
304
328
|
|
305
329
|
private
|
306
330
|
|
307
|
-
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]
|
308
482
|
end
|
309
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,22 +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/
|
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/type_checker.rb
|
49
|
+
- lib/bcdd/result/expectations/mixin.rb
|
43
50
|
- lib/bcdd/result/failure.rb
|
51
|
+
- lib/bcdd/result/failure/methods.rb
|
44
52
|
- lib/bcdd/result/handler.rb
|
45
53
|
- lib/bcdd/result/handler/allowed_types.rb
|
46
54
|
- lib/bcdd/result/mixin.rb
|
47
55
|
- lib/bcdd/result/success.rb
|
56
|
+
- lib/bcdd/result/success/methods.rb
|
48
57
|
- lib/bcdd/result/version.rb
|
49
58
|
- lib/result.rb
|
50
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
|