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 +4 -4
- data/lib/optify_from_hash/from_hashable.rb +16 -8
- 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: 1f6e409cfccf83b515e84d3cc19713e1897ed53cf4340d66de2843433c355445
|
|
4
|
+
data.tar.gz: 630ed4471403551570ba2f18d3ec687ba4790dec90332496d6f9d39100f353f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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.
|