optify-from_hash 0.2.1 → 0.2.2

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: 0e24ce9b23b87819fc6688195ca5a90cb43dfbe23b25264e269cf37daa97f531
4
- data.tar.gz: 18e142eb6c75bf80cfab5fb8d64079ec1f7fd2d212e97043def5555d595fcdd0
3
+ metadata.gz: 1f6e409cfccf83b515e84d3cc19713e1897ed53cf4340d66de2843433c355445
4
+ data.tar.gz: 630ed4471403551570ba2f18d3ec687ba4790dec90332496d6f9d39100f353f5
5
5
  SHA512:
6
- metadata.gz: ecfa102d64db21405131a02545bfa524eebde5150c9030555faa89e8e802ec6bdf8006fbd90d30a713450a1beb28167302996bbee2507c01f6d67cea3196ad56
7
- data.tar.gz: 1943ab3ab4ec77e5441de4006b1699683a5bf0d9e8151d3b51ef4fcedd00e6eedf5b8baa5e9d42e7edff367f22d29109495e63ee2e6cff197facd2f5edd8ed79
6
+ metadata.gz: b9414cd9843a25f5b1ed1ab7f1560d5e73c0f85b3900859daa786c03f02bfd04dbc4947120bf519c8ff5f80b3712947b3b53a20c778b1e8e354c259b7c266e19
7
+ data.tar.gz: de4275bb6b2300dfa3e154dbc04ec49120d28ec3f20e17e537c51e1cde5a065772eaad10269abdeb8fa7a528043b376a49d2c2655d810b47373137f322a39fdc
@@ -46,16 +46,13 @@ module Optify
46
46
  return value
47
47
  end
48
48
 
49
- return value.to_sym if type.is_a?(T::Types::Simple) && type.raw_type == Symbol
49
+ unwrapped_type = _unwrap_nilable(type)
50
+ return value&.to_sym if unwrapped_type.is_a?(T::Types::Simple) && unwrapped_type.raw_type == Symbol
50
51
 
51
52
  case value
52
53
  when Array
53
- # Handle `T.nilable(T::Array[...])`
54
- if type.respond_to?(:unwrap_nilable)
55
- type = type #: as untyped
56
- .unwrap_nilable
57
- end
58
- inner_type = type.type
54
+ inner_type = unwrapped_type #: as untyped
55
+ .type
59
56
  return value.map { |v| _convert_value(v, inner_type) }.freeze
60
57
  when Hash
61
58
  # Handle `T.nilable(T::Hash[...])` and `T.any(...)`.
@@ -104,7 +101,18 @@ module Optify
104
101
  raise TypeError, "Could not convert hash #{hash} to `#{type}`."
105
102
  end
106
103
 
107
- private_class_method :_convert_hash, :_convert_value
104
+ # Unwrap `T.nilable(...)` to get the inner type, or return the type as-is.
105
+ #: (T::Types::Base) -> T::Types::Base
106
+ def self._unwrap_nilable(type)
107
+ if type.respond_to?(:unwrap_nilable)
108
+ type #: as untyped
109
+ .unwrap_nilable
110
+ else
111
+ type
112
+ end
113
+ end
114
+
115
+ private_class_method :_convert_hash, :_convert_value, :_unwrap_nilable
108
116
 
109
117
  # Compare this object with another object for equality.
110
118
  # @param other The object to compare.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optify-from_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin D. Harris