attributor 6.3 → 6.4
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 +3 -0
- 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: 7299ae5b05648dd2b4dd2f787734222f4037458a8531440a7891b3d9adfbda47
|
4
|
+
data.tar.gz: cfa9c950f3628426bf1b8b00d9ea61cd2304ce7636eaf976fb993432fdd739bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e840b98417976fd4fb49ca16b3c5863c0c3e3c76ef349771a2c189dec2795759186a80da6cc59320c834ad7bf68a013d2ed9f927ed1a0e55bb83c5dbb83b4470
|
7
|
+
data.tar.gz: 1243afa58fb5a4f8309d66b3654d29dcda8542c655d99ed3351cb12ffc9541859aac8a736024f5e3789c013d73c2f1d0879cf4a8ded8dd93038282fcb0537657
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
## next
|
4
4
|
|
5
|
+
## 6.4 (10/26/2022)
|
6
|
+
- Cache default values for a type, to speedup loading/coercing an object to it
|
7
|
+
|
5
8
|
## 6.3 (10/21/2022)
|
6
9
|
- Added some small utility enhancements for dealing with attributes and types
|
7
10
|
* .duplicate an attribute, with a different inner type and/or options
|
@@ -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.4'
|
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: 2022-10-
|
12
|
+
date: 2022-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|