attributor 6.3 → 6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b30fd80bf80e1fba073207107cc6ee008d8f7f5edc3acd49863d58d27c9b2caa
4
- data.tar.gz: 7549362dfe5fb7f1eb654ab7927996baee065f4b37cbdb74fcfb472189b8ea17
3
+ metadata.gz: 7299ae5b05648dd2b4dd2f787734222f4037458a8531440a7891b3d9adfbda47
4
+ data.tar.gz: cfa9c950f3628426bf1b8b00d9ea61cd2304ce7636eaf976fb993432fdd739bf
5
5
  SHA512:
6
- metadata.gz: 46fb615c0952564d354ed67e9ed4e794bead86868111cf3a1447f1aab92e9a8106addca135673b59acb67f58dfdbbc5ed8a49d9f5f5cebdf5a2439719c495768
7
- data.tar.gz: 726a29e1f6a30025f51a62dfb63fc8331e3202a3553f031ad776679ee7a525a7e689feb75ed184d0eb306b6bbe6b7c03605bb6b396fd5e234e0ddc1fa751b2e8
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
- sub_context = generate_subcontext(context, key_name)
423
- default = attribute.load(nil, sub_context, recurse: recurse)
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
 
@@ -46,6 +46,7 @@ module Attributor
46
46
  @value_attribute = va
47
47
 
48
48
  @requirements = []
49
+ @cached_defaults = {}
49
50
  @error = false
50
51
  end
51
52
  end
@@ -1,3 +1,3 @@
1
1
  module Attributor
2
- VERSION = '6.3'.freeze
2
+ VERSION = '6.4'.freeze
3
3
  end
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.3'
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-21 00:00:00.000000000 Z
12
+ date: 2022-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie