attributor 7.0 → 7.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/CHANGELOG.md +5 -0
- data/lib/attributor/attribute.rb +11 -0
- data/lib/attributor/types/float.rb +1 -1
- data/lib/attributor/version.rb +1 -1
- data/spec/attribute_spec.rb +10 -0
- data/spec/types/float_spec.rb +4 -2
- 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: 6207241fe519ee3ee26e4a4220077428c26850c556abd065d7c073125c0a49fa
|
4
|
+
data.tar.gz: bb19a849faf087d1f9fad40c9b3101b4a416ef32ef8f4d266b6a061c37f270e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bbec43bae528b47ddc5176e75bbd07f84707520a363e08257dff88409d1a7b1f9febce1a77e2a99e4df07537d0ed6253d4e6911e453a51f28bcb3f7d445b6ff
|
7
|
+
data.tar.gz: 12726d8e722d4ddc28c04bb6d03d3fae81b5f4abe84268f1e335f80a6e84880dcddc96ca12a9d1281abf4fac31c900d644c2f3e1ef9e1ff0d1929aeae0afe325
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## next
|
4
4
|
|
5
|
+
## 7.1 (6/9/2023)
|
6
|
+
- Enhance custom_option handling. The values provided for custom options are now loaded (and definition will fail if they aren't compatible). This was specially
|
7
|
+
important for custom options that were collections, etc.
|
8
|
+
- Fix Float type .load
|
9
|
+
|
5
10
|
## 7.0 (5/23/2023)
|
6
11
|
- Support for loading "<digits>." strings in BigDecimal/Float types (These are formats supported by JS, Java ..)
|
7
12
|
- Support for defining collections of types using a more terse DSL: T[]
|
data/lib/attributor/attribute.rb
CHANGED
@@ -42,6 +42,17 @@ module Attributor
|
|
42
42
|
@type = Attributor.resolve_type(type, options, block)
|
43
43
|
@options = @type.respond_to?(:options) ? @type.options.merge(options) : options
|
44
44
|
|
45
|
+
# We will give the values passed for options, a chance to be 'loaded' by its type, so we store native loaded values in the options
|
46
|
+
begin
|
47
|
+
current_option_name = nil # Use this to avoid having to wrap each loop with a begin/rescue block
|
48
|
+
(self.class.custom_options.keys & @options.keys).each do |custom_key|
|
49
|
+
current_option_name = custom_key
|
50
|
+
@options[custom_key] = self.class.custom_options[custom_key].load(@options[custom_key])
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
raise AttributorException, "Error while loading value #{@options[current_option_name]} for custom option '#{current_option_name}': #{e.message}"
|
54
|
+
end
|
55
|
+
|
45
56
|
check_options!
|
46
57
|
end
|
47
58
|
|
@@ -18,7 +18,7 @@ module Attributor
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
|
21
|
-
return
|
21
|
+
return Float(value + '0') if value.is_a?(::String) && value.end_with?('.')
|
22
22
|
Float(value)
|
23
23
|
rescue TypeError
|
24
24
|
super
|
data/lib/attributor/version.rb
CHANGED
data/spec/attribute_spec.rb
CHANGED
@@ -232,6 +232,16 @@ describe Attributor::Attribute do
|
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
+
context 'validates the type of values' do
|
236
|
+
let(:custom_option_args) { [option_name, String ] }
|
237
|
+
|
238
|
+
it 'raises with an invalid option value' do
|
239
|
+
expect do
|
240
|
+
Attributor::Attribute.new(Integer, foo: {a:1})
|
241
|
+
end.to raise_error(Attributor::AttributorException,/Error while loading value {:a=>1} for custom option 'foo': Type Attributor::String cannot load values of type Hash/)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
235
245
|
it 'appear in as_json_schema' do
|
236
246
|
attribute = Attributor::Attribute.new(Integer, foo: 'valid')
|
237
247
|
json_schema = attribute.as_json_schema
|
data/spec/types/float_spec.rb
CHANGED
@@ -61,8 +61,10 @@ describe Attributor::Float do
|
|
61
61
|
expect(type.load('0.')).to eq Float('0.0')
|
62
62
|
end
|
63
63
|
it 'decodes it if the String represents a negative Float and ends in .' do
|
64
|
-
expect(type.load('-10.')).to eq
|
65
|
-
expect(type.load('-
|
64
|
+
expect(type.load('-10.')).to eq -10.0
|
65
|
+
expect(type.load('-10.').class).to eq Float
|
66
|
+
expect(type.load('-0.')).to eq -0.0
|
67
|
+
expect(type.load('-0.').class).to eq Float
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attributor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '7.
|
4
|
+
version: '7.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|