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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06b0c152c2da68e05379b49921b5c1daad165f8322533b162712e090b01ee13e
4
- data.tar.gz: 23122f0746864b8b8f35c105279a6f825a9fb35791a33dd8bb754b78f8609b0f
3
+ metadata.gz: a07fce97adead2a0d6b77c83f0c80c06d6ecb6633193f61454d961bea1a4acf2
4
+ data.tar.gz: c6c66f5a03d8bea908b6b68cbe76c69f724012313348c3563bade4932946acc8
5
5
  SHA512:
6
- metadata.gz: b27d4be530cc22d8ed186a732e5fb3b8051b0e6586ddcabb321ece29393457402bd991e9e1ef415ac44fcf30d496ff1504d1078278fc7ad49867b8078ddce7ac
7
- data.tar.gz: 7e4849a426e904b6fcb2a516bf99cf13ff9205920f6265361ec5b0203e242af0f386df67a476c5fb241f372d377303a8ba09b75602d5685113b759a2dd7aad8c
6
+ metadata.gz: 8d6d7dbac95eeea0d1fcb1bade820a2c7ba83e464dda0d79052a7beee9f9a67bc4c53c1b87b38256189ffd8f8d6bf0e8f40dc2055db1395f2bc227c30a2075bf
7
+ data.tar.gz: 522f8e75d45b543d1d8762be130d6a625dac1b8ac47a7b3eae5729649afedd8d0e493ecbb885b1aef42a887fc6a4a8ab4461ab0fd615d40d413b91da93da6ebf
data/gemset.nix CHANGED
@@ -269,7 +269,7 @@
269
269
  path = ./.;
270
270
  type = "path";
271
271
  };
272
- version = "0.4.2";
272
+ version = "0.5.0";
273
273
  };
274
274
  erubi = {
275
275
  groups = ["default" "development"];
@@ -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
@@ -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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Errgonomic
4
- VERSION = '0.4.2'
4
+ VERSION = '0.5.0'
5
5
  end
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 < Error; end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errgonomic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Zadrozny