errgonomic 0.4.2 → 0.5.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/gemset.nix +1 -1
- data/lib/errgonomic/option.rb +20 -0
- data/lib/errgonomic/rails/active_record_optional.rb +0 -8
- data/lib/errgonomic/result.rb +22 -0
- data/lib/errgonomic/version.rb +1 -1
- data/lib/errgonomic.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a07fce97adead2a0d6b77c83f0c80c06d6ecb6633193f61454d961bea1a4acf2
|
|
4
|
+
data.tar.gz: c6c66f5a03d8bea908b6b68cbe76c69f724012313348c3563bade4932946acc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d6d7dbac95eeea0d1fcb1bade820a2c7ba83e464dda0d79052a7beee9f9a67bc4c53c1b87b38256189ffd8f8d6bf0e8f40dc2055db1395f2bc227c30a2075bf
|
|
7
|
+
data.tar.gz: 522f8e75d45b543d1d8762be130d6a625dac1b8ac47a7b3eae5729649afedd8d0e493ecbb885b1aef42a887fc6a4a8ab4461ab0fd615d40d413b91da93da6ebf
|
data/gemset.nix
CHANGED
data/lib/errgonomic/option.rb
CHANGED
|
@@ -321,6 +321,26 @@ module Errgonomic
|
|
|
321
321
|
Some(other)
|
|
322
322
|
end
|
|
323
323
|
|
|
324
|
+
# Refuse to serialize an unwrapped Option as a String. Options must be
|
|
325
|
+
# correctly handled to access their inner value.
|
|
326
|
+
#
|
|
327
|
+
# @example
|
|
328
|
+
# None().to_s # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Option"
|
|
329
|
+
def to_s
|
|
330
|
+
raise Errgonomic::SerializeError, 'cannot serialize an unwrapped Option'
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# Refuse to serialize an unwrapped Option as JSON. Not only should we
|
|
334
|
+
# require that options be correctly handled to access their inner value,
|
|
335
|
+
# but without this we will get undefined structures from default
|
|
336
|
+
# Object#to_json implementations.
|
|
337
|
+
#
|
|
338
|
+
# @example
|
|
339
|
+
# None().to_json # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Option"
|
|
340
|
+
def to_json(*_args)
|
|
341
|
+
raise Errgonomic::SerializeError, 'cannot serialize an unwrapped Option'
|
|
342
|
+
end
|
|
343
|
+
|
|
324
344
|
# filter
|
|
325
345
|
# xor
|
|
326
346
|
# insert
|
|
@@ -53,20 +53,12 @@ module Errgonomic
|
|
|
53
53
|
delegate :marked_for_destruction?, to: :value
|
|
54
54
|
delegate :persisted?, to: :value
|
|
55
55
|
delegate :touch_later, to: :value
|
|
56
|
-
|
|
57
|
-
def to_s
|
|
58
|
-
raise "Attempted to convert Some to String, please use Option API to safely work with internal value -- #{value}"
|
|
59
|
-
end
|
|
60
56
|
end
|
|
61
57
|
|
|
62
58
|
class None
|
|
63
59
|
def nil?
|
|
64
60
|
true
|
|
65
61
|
end
|
|
66
|
-
|
|
67
|
-
def to_s
|
|
68
|
-
raise 'Cannot convert None to String - please use Option API to safely work with internal value'
|
|
69
|
-
end
|
|
70
62
|
end
|
|
71
63
|
end
|
|
72
64
|
end
|
data/lib/errgonomic/result.rb
CHANGED
|
@@ -252,6 +252,28 @@ module Errgonomic
|
|
|
252
252
|
@value = block.call(value)
|
|
253
253
|
self
|
|
254
254
|
end
|
|
255
|
+
|
|
256
|
+
# Refuse to serialize an unwrapped Result as a String. Results must be
|
|
257
|
+
# correctly handled to access their inner value.
|
|
258
|
+
#
|
|
259
|
+
# @example
|
|
260
|
+
# Ok("").to_s # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Result"
|
|
261
|
+
# Err("").to_s # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Result"
|
|
262
|
+
def to_s
|
|
263
|
+
raise Errgonomic::SerializeError, 'cannot serialize an unwrapped Result'
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Refuse to serialize an unwrapped Result as JSON. Not only should we
|
|
267
|
+
# require that Results be correctly handled to access their inner value,
|
|
268
|
+
# but without this we will get undefined structures from default
|
|
269
|
+
# Object#to_json implementations.
|
|
270
|
+
#
|
|
271
|
+
# @example
|
|
272
|
+
# Ok("").to_json # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Result"
|
|
273
|
+
# Err("").to_json # => raise Errgonomic::SerializeError, "cannot serialize an unwrapped Result"
|
|
274
|
+
def to_json(*_args)
|
|
275
|
+
raise Errgonomic::SerializeError, 'cannot serialize an unwrapped Result'
|
|
276
|
+
end
|
|
255
277
|
end
|
|
256
278
|
|
|
257
279
|
# The Ok variant.
|
data/lib/errgonomic/version.rb
CHANGED
data/lib/errgonomic.rb
CHANGED
|
@@ -23,9 +23,11 @@ require_relative 'errgonomic/rails' if defined?(Rails::Railtie)
|
|
|
23
23
|
module Errgonomic
|
|
24
24
|
class Error < StandardError; end
|
|
25
25
|
|
|
26
|
+
class TypeError < ::TypeError; end
|
|
27
|
+
|
|
26
28
|
class NotPresentError < Error; end
|
|
27
29
|
|
|
28
|
-
class TypeMismatchError <
|
|
30
|
+
class TypeMismatchError < TypeError; end
|
|
29
31
|
|
|
30
32
|
class UnwrapError < Error
|
|
31
33
|
def initialize(msg, value)
|
|
@@ -42,6 +44,8 @@ module Errgonomic
|
|
|
42
44
|
|
|
43
45
|
class NotComparableError < StandardError; end
|
|
44
46
|
|
|
47
|
+
class SerializeError < TypeError; end
|
|
48
|
+
|
|
45
49
|
# A little bit of control over how pedantic we are in our runtime type checks.
|
|
46
50
|
def self.give_me_ambiguous_downstream_errors?
|
|
47
51
|
@give_me_ambiguous_downstream_errors || true
|