bcdd-result 0.4.0 → 0.5.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 +21 -0
- data/.rubocop_todo.yml +3 -13
- data/CHANGELOG.md +74 -0
- data/README.md +407 -10
- data/lib/bcdd/result/data.rb +12 -7
- data/lib/bcdd/result/error.rb +8 -0
- 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/type_checker.rb +33 -0
- data/lib/bcdd/result/expectations.rb +62 -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/success.rb +1 -1
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +18 -16
- data/sig/bcdd/result.rbs +200 -41
- metadata +12 -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
|
@@ -27,9 +33,7 @@ class BCDD::Result
|
|
27
33
|
|
28
34
|
def and_then: (?Symbol method_name) { (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
|
@@ -71,40 +75,6 @@ class BCDD::Result
|
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
74
|
-
class BCDD::Result
|
75
|
-
class Handler
|
76
|
-
UNDEFINED: Object
|
77
|
-
|
78
|
-
def initialize: (BCDD::Result) -> void
|
79
|
-
|
80
|
-
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
81
|
-
def failure: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
82
|
-
def success: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
83
|
-
def unknown: () { (untyped, Symbol) -> void } -> untyped
|
84
|
-
|
85
|
-
alias type []
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
attr_reader _type: BCDD::Result::Type
|
90
|
-
attr_reader result: BCDD::Result
|
91
|
-
|
92
|
-
def outcome?: -> bool
|
93
|
-
def outcome=: (Proc) -> void
|
94
|
-
def outcome: -> untyped
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class BCDD::Result
|
99
|
-
class Type
|
100
|
-
attr_reader to_sym: Symbol
|
101
|
-
|
102
|
-
def initialize: (Symbol) -> void
|
103
|
-
|
104
|
-
def in?: (Array[Symbol], allow_empty: bool) -> bool
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
78
|
class BCDD::Result
|
109
79
|
class Data
|
110
80
|
attr_reader name: Symbol
|
@@ -113,7 +83,7 @@ class BCDD::Result
|
|
113
83
|
attr_reader to_h: Hash[Symbol, untyped]
|
114
84
|
attr_reader to_a: [Symbol, Symbol, untyped]
|
115
85
|
|
116
|
-
def initialize: (
|
86
|
+
def initialize: (Symbol, Symbol, untyped) -> void
|
117
87
|
|
118
88
|
def inspect: -> String
|
119
89
|
|
@@ -146,5 +116,194 @@ class BCDD::Result
|
|
146
116
|
def self.build: (subject: untyped, method: ::Method)
|
147
117
|
-> BCDD::Result::Error::WrongSubjectMethodArity
|
148
118
|
end
|
119
|
+
|
120
|
+
class UnhandledTypes < BCDD::Result::Error
|
121
|
+
def self.build: (types: Set[Symbol])
|
122
|
+
-> BCDD::Result::Error::UnhandledTypes
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class BCDD::Result
|
128
|
+
class Handler
|
129
|
+
UNDEFINED: Object
|
130
|
+
|
131
|
+
def initialize: (
|
132
|
+
BCDD::Result,
|
133
|
+
type_checker: BCDD::Result::Expectations::TypeChecker
|
134
|
+
) -> void
|
135
|
+
|
136
|
+
def []: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
137
|
+
def failure: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
138
|
+
def success: (*Symbol) { (untyped, Symbol) -> void } -> untyped
|
139
|
+
def unknown: () { (untyped, Symbol) -> void } -> untyped
|
140
|
+
|
141
|
+
alias type []
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
attr_reader result: BCDD::Result
|
146
|
+
attr_reader allowed_types: BCDD::Result::Handler::AllowedTypes
|
147
|
+
|
148
|
+
def outcome?: -> bool
|
149
|
+
def outcome=: (Proc) -> void
|
150
|
+
def outcome: -> untyped
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class BCDD::Result::Handler
|
155
|
+
class AllowedTypes
|
156
|
+
attr_reader unchecked: Set[Symbol]
|
157
|
+
attr_reader type_checker: BCDD::Result::Expectations::TypeChecker
|
158
|
+
|
159
|
+
def initialize: (
|
160
|
+
BCDD::Result::Expectations::TypeChecker
|
161
|
+
) -> void
|
162
|
+
|
163
|
+
def allow?: (Array[Symbol]) -> bool
|
164
|
+
def allow_success?: (Array[Symbol]) -> bool
|
165
|
+
def allow_failure?: (Array[Symbol]) -> bool
|
166
|
+
|
167
|
+
def all_checked?: -> bool
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def check!: (Array[Symbol], bool) -> bool
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class BCDD::Result::Expectations
|
176
|
+
MIXIN_METHODS: String
|
177
|
+
|
178
|
+
def self.mixin: (
|
179
|
+
?success: Hash[Symbol, untyped] | Array[Symbol],
|
180
|
+
?failure: Hash[Symbol, untyped] | Array[Symbol]
|
181
|
+
) -> Module
|
182
|
+
|
183
|
+
def self.evaluate: (
|
184
|
+
BCDD::Result::Data,
|
185
|
+
BCDD::Result::Expectations::Contract::Evaluator
|
186
|
+
) -> BCDD::Result::Expectations::TypeChecker
|
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
|
206
|
+
|
207
|
+
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol])
|
208
|
+
-> BCDD::Result::Expectations::Contract::Evaluator
|
209
|
+
|
210
|
+
def self.new: (
|
211
|
+
success: Hash[Symbol, untyped] | Array[Symbol],
|
212
|
+
failure: Hash[Symbol, untyped] | Array[Symbol]
|
213
|
+
) -> BCDD::Result::Expectations::Contract::Evaluator
|
214
|
+
end
|
215
|
+
|
216
|
+
class BCDD::Result::Expectations
|
217
|
+
class TypeChecker
|
218
|
+
attr_reader result_type: Symbol
|
219
|
+
attr_reader expectations: BCDD::Result::Expectations::Contract::Evaluator
|
220
|
+
|
221
|
+
def initialize: (
|
222
|
+
Symbol,
|
223
|
+
expectations: BCDD::Result::Expectations::Contract::Evaluator
|
224
|
+
) -> void
|
225
|
+
|
226
|
+
def allow?: (Array[Symbol]) -> bool
|
227
|
+
def allow_success?: (Array[Symbol]) -> bool
|
228
|
+
def allow_failure?: (Array[Symbol]) -> bool
|
229
|
+
|
230
|
+
private
|
231
|
+
|
232
|
+
def validate: (
|
233
|
+
Array[Symbol],
|
234
|
+
expected: BCDD::Result::Expectations::Contract::Interface,
|
235
|
+
allow_empty: bool
|
236
|
+
) -> bool
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
class BCDD::Result::Expectations::Error < BCDD::Result::Error
|
241
|
+
class UnexpectedType < BCDD::Result::Expectations::Error
|
242
|
+
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
243
|
+
-> BCDD::Result::Expectations::Error::UnexpectedType
|
244
|
+
end
|
245
|
+
|
246
|
+
class UnexpectedValue < BCDD::Result::Expectations::Error
|
247
|
+
def self.build: (type: Symbol, value: untyped)
|
248
|
+
-> BCDD::Result::Expectations::Error::UnexpectedValue
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
module BCDD::Result::Expectations::Contract
|
253
|
+
module Interface
|
254
|
+
def ==: (BCDD::Result::Expectations::Contract::Interface) -> bool
|
255
|
+
|
256
|
+
def allowed_types: -> Set[Symbol]
|
257
|
+
|
258
|
+
def type?: (Symbol) -> bool
|
259
|
+
|
260
|
+
def type!: (Symbol) -> Symbol
|
261
|
+
|
262
|
+
def type_and_value!: (BCDD::Result::Data) -> void
|
263
|
+
|
264
|
+
def !=: (untyped) -> bool
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
module BCDD::Result::Expectations::Contract
|
269
|
+
module Disabled
|
270
|
+
extend Interface
|
271
|
+
|
272
|
+
EMPTY_SET: Set[Symbol]
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
module BCDD::Result::Expectations::Contract
|
277
|
+
class ForTypes
|
278
|
+
include Interface
|
279
|
+
|
280
|
+
def initialize: (Array[Symbol]) -> void
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
module BCDD::Result::Expectations::Contract
|
285
|
+
class ForTypesAndValues
|
286
|
+
include Interface
|
287
|
+
|
288
|
+
def initialize: (Hash[Symbol, untyped]) -> void
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
module BCDD::Result::Expectations::Contract
|
293
|
+
class Evaluator
|
294
|
+
include Interface
|
295
|
+
|
296
|
+
attr_reader allowed_types: Set[Symbol]
|
297
|
+
attr_reader success: BCDD::Result::Expectations::Contract::Interface
|
298
|
+
attr_reader failure: BCDD::Result::Expectations::Contract::Interface
|
299
|
+
|
300
|
+
def initialize: (
|
301
|
+
BCDD::Result::Expectations::Contract::Interface,
|
302
|
+
BCDD::Result::Expectations::Contract::Interface
|
303
|
+
) -> void
|
304
|
+
|
305
|
+
private
|
306
|
+
|
307
|
+
def for: (BCDD::Result::Data) -> BCDD::Result::Expectations::Contract::Interface
|
149
308
|
end
|
150
309
|
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.5.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-10 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,20 @@ 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/type_checker.rb
|
34
43
|
- lib/bcdd/result/failure.rb
|
35
44
|
- lib/bcdd/result/handler.rb
|
45
|
+
- lib/bcdd/result/handler/allowed_types.rb
|
36
46
|
- lib/bcdd/result/mixin.rb
|
37
47
|
- lib/bcdd/result/success.rb
|
38
|
-
- lib/bcdd/result/type.rb
|
39
48
|
- lib/bcdd/result/version.rb
|
40
49
|
- lib/result.rb
|
41
50
|
- 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
|