vident 0.5.0 → 0.5.1
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/vident/attributes/typed.rb +23 -14
- data/lib/vident/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81f442775cc3413603ea1770059483978615f37809502245cca2f1ac8ddd868
|
4
|
+
data.tar.gz: 37ce0a04d8a8e37cfdc10f5b5174f771e93ecb2c8dd8909eb58ef842866d0ae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec38a1d6550386705dd6de2374d650ee890c147c9cf97cca299b01bf27616f2becccdebe273efa51153ad74ace43faef8006464a5a2418e9991ca3642fdb8dca
|
7
|
+
data.tar.gz: a1b01b01507a70e276ec14b6a358c520f1bc11aca8c713fe32bb5a0091230caf9fd38e8f4ef22beed50ed8a1f72c0bb48c40cd5e10cdfaa546dafe80780af337
|
@@ -61,9 +61,11 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
61
61
|
attr_reader :schema, :attribute_ivar_names
|
62
62
|
|
63
63
|
def attribute(name, signature = :any, **options, &converter)
|
64
|
-
|
64
|
+
strict = !options[:convert]
|
65
|
+
signatures = extract_member_type_and_subclass(signature, options)
|
66
|
+
type_info = map_primitive_to_dry_type(signatures, strict, converter)
|
65
67
|
type_info = set_constraints(type_info, options)
|
66
|
-
type_info = set_metadata(type_info,
|
68
|
+
type_info = set_metadata(type_info, signatures, options)
|
67
69
|
define_on_schema(name, type_info, options)
|
68
70
|
end
|
69
71
|
|
@@ -87,8 +89,8 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
87
89
|
type_info
|
88
90
|
end
|
89
91
|
|
90
|
-
def set_metadata(type_info,
|
91
|
-
metadata = {typed_attribute_type:
|
92
|
+
def set_metadata(type_info, signatures, options)
|
93
|
+
metadata = {typed_attribute_type: signatures, typed_attribute_options: options}
|
92
94
|
type_info.meta(**metadata)
|
93
95
|
end
|
94
96
|
|
@@ -100,7 +102,7 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
100
102
|
@attribute_ivar_names ||= {}
|
101
103
|
@attribute_ivar_names[attribute_name] = :"@#{attribute_name}"
|
102
104
|
define_attribute_delegate(attribute_name) if delegates?(options)
|
103
|
-
@schema ||= const_set(
|
105
|
+
@schema ||= const_set(:TypedSchema, Class.new(Vident::Attributes::TypedNilingStruct))
|
104
106
|
@schema.attribute attribute_name, type_info
|
105
107
|
end
|
106
108
|
|
@@ -130,9 +132,7 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
130
132
|
allow_blank.nil? ? true : allow_blank
|
131
133
|
end
|
132
134
|
|
133
|
-
def map_primitive_to_dry_type(
|
134
|
-
strict = !options[:convert]
|
135
|
-
signatures = extract_member_type_and_subclass(signature, options)
|
135
|
+
def map_primitive_to_dry_type(signatures, strict, converter)
|
136
136
|
types = signatures.map do |type, subtype|
|
137
137
|
dry_type = dry_type_from_primary_type(type, strict, converter)
|
138
138
|
if subtype && dry_type.respond_to?(:of)
|
@@ -158,6 +158,19 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def dry_type_from_primary_type(type, strict, converter)
|
161
|
+
# If a converter is provided, we should use it to coerce the value
|
162
|
+
if converter && !strict && !type.is_a?(Symbol)
|
163
|
+
return Types.Constructor(type) do |value|
|
164
|
+
next value if value.is_a?(type)
|
165
|
+
|
166
|
+
converter.call(value).tap do |new_value|
|
167
|
+
unless new_value.is_a?(type)
|
168
|
+
raise ArgumentError, "Type conversion proc did not convert #{value} to #{type}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
161
174
|
if type == :any
|
162
175
|
Types::Nominal::Any
|
163
176
|
elsif type == Integer
|
@@ -191,15 +204,11 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
191
204
|
# values using the default constructor, `new`.
|
192
205
|
Types.Instance(type)
|
193
206
|
else
|
194
|
-
# dry calls this when initialising the Type. Check if type of input is correct or
|
207
|
+
# dry calls this when initialising the Type. Check if type of input is correct or create new instance
|
195
208
|
Types.Constructor(type) do |value|
|
196
209
|
next value if value.is_a?(type)
|
197
210
|
|
198
|
-
|
199
|
-
converter.call(value)
|
200
|
-
else
|
201
|
-
type.new(**value)
|
202
|
-
end
|
211
|
+
type.new(**value)
|
203
212
|
end
|
204
213
|
end
|
205
214
|
end
|
data/lib/vident/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|