attributor 6.3 → 6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/attributor/types/bigdecimal.rb +15 -3
- data/lib/attributor/types/hash.rb +13 -4
- data/lib/attributor/types/model.rb +1 -0
- data/lib/attributor/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: 9242ef6d878ab79e69393d7bf31b6459873d39a8307c9dac0ea05ce8c4a01912
|
4
|
+
data.tar.gz: 0b2f333abe4957d1575df87c734c4f642274a83d50562059c33fb261154e44a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48a0ea86f5550dd44b0d162ea96c1a98bbd7019955857f607817efe921fc4250c210e2591664d18a9388fd614d323547c83421b64ba678369c47d248423770ca
|
7
|
+
data.tar.gz: dcd17fa9b98e35d02e471ef340b641ba15ff4fafd6f05d5ac650204830ba7cc7a44feaf40b6a2386c660ab17d3b8d0b881d01d84c4a83a46fe41c6552a2ec74d
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## next
|
4
4
|
|
5
|
+
## 6.5 (1/19/2023)
|
6
|
+
- Fix JSON schema reporting for BigDecimal types to be a string, with a format=bigdecimal
|
7
|
+
|
8
|
+
## 6.4 (10/26/2022)
|
9
|
+
- Cache default values for a type, to speedup loading/coercing an object to it
|
10
|
+
|
5
11
|
## 6.3 (10/21/2022)
|
6
12
|
- Added some small utility enhancements for dealing with attributes and types
|
7
13
|
* .duplicate an attribute, with a different inner type and/or options
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'bigdecimal'
|
2
2
|
|
3
3
|
module Attributor
|
4
|
-
class BigDecimal
|
5
|
-
include
|
4
|
+
class BigDecimal
|
5
|
+
include Type
|
6
|
+
|
6
7
|
def self.native_type
|
7
8
|
::BigDecimal
|
8
9
|
end
|
@@ -19,7 +20,18 @@ module Attributor
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def self.json_schema_type
|
22
|
-
:
|
23
|
+
:string
|
24
|
+
end
|
25
|
+
|
26
|
+
# Bigdecimal numbers are too big to be represented as numbers in JSON schema
|
27
|
+
# The way to do so, is to represent them as strings, but add a 'format' specifying
|
28
|
+
# how to parse that (seemingly, there is a 'double' well known type that json API
|
29
|
+
# claims we can use) ... not sure if this is the right one, as technically BigDecimal
|
30
|
+
# has very large precision that a double wouldn't be able to fit...
|
31
|
+
def self.as_json_schema( shallow: false, example: nil, attribute_options: {} )
|
32
|
+
hash = super
|
33
|
+
hash[:format] = 'bigdecimal'
|
34
|
+
hash
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
@@ -30,6 +30,7 @@ module Attributor
|
|
30
30
|
attr_reader :insensitive_map
|
31
31
|
attr_accessor :extra_keys
|
32
32
|
attr_reader :requirements
|
33
|
+
attr_reader :cached_defaults
|
33
34
|
end
|
34
35
|
|
35
36
|
@key_type = Object
|
@@ -40,6 +41,7 @@ module Attributor
|
|
40
41
|
|
41
42
|
@error = false
|
42
43
|
@requirements = []
|
44
|
+
@cached_defaults = {}
|
43
45
|
|
44
46
|
def self.slice!(*keys)
|
45
47
|
missing_keys = keys - @keys.keys
|
@@ -81,7 +83,7 @@ module Attributor
|
|
81
83
|
@key_attribute = Attribute.new(@key_type)
|
82
84
|
@value_attribute = Attribute.new(@value_type)
|
83
85
|
@requirements = []
|
84
|
-
|
86
|
+
@cached_defaults = {}
|
85
87
|
@error = false
|
86
88
|
end
|
87
89
|
end
|
@@ -419,14 +421,21 @@ module Attributor
|
|
419
421
|
# handle default values for missing keys
|
420
422
|
keys.each do |key_name, attribute|
|
421
423
|
next if hash.key?(key_name)
|
422
|
-
|
423
|
-
default
|
424
|
+
|
425
|
+
# Cache default values to avoid a whole loading call for the attribute
|
426
|
+
default = if @cached_defaults.key?(key_name)
|
427
|
+
@cached_defaults[key_name]
|
428
|
+
else
|
429
|
+
sub_context = generate_subcontext(context, key_name)
|
430
|
+
@cached_defaults[key_name] = attribute.load(nil, sub_context, recurse: recurse)
|
431
|
+
end
|
424
432
|
hash[key_name] = default unless default.nil?
|
425
433
|
end
|
426
|
-
|
427
434
|
hash
|
428
435
|
end
|
429
436
|
|
437
|
+
|
438
|
+
|
430
439
|
def self.validate(object, context = Attributor::DEFAULT_ROOT_CONTEXT, _attribute)
|
431
440
|
context = [context] if context.is_a? ::String
|
432
441
|
|
data/lib/attributor/version.rb
CHANGED
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: '6.
|
4
|
+
version: '6.5'
|
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:
|
12
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|