dry-configurable 0.16.0 → 0.16.1

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: 323f300c1cf0cf407272352b81dd0775ac7f855713cd6145fccc9d11dbdae8cf
4
- data.tar.gz: b8258cfa9a30108831384e575a00e5afd93b9d94942d52799d23013e3753ceaf
3
+ metadata.gz: 0d8c3e4ebee8cf7f978c48580f64c1547c6c818b50ed7064b0758b4bffb072ee
4
+ data.tar.gz: 2aa701383b59289fbe591100642027fc5bc0d074bd0ec5d6d085359293af0f8f
5
5
  SHA512:
6
- metadata.gz: d37acc7d39adb1ed1f0da218c5f16ac0e6d09832e70e73220770fa28ad8eff4f21f440a6285b22785de82f76a8df6f444d37024d5059fdc2ba3f3b3006fd19c9
7
- data.tar.gz: c7888430539dfa30f4518ca159cae0675d2766ec8c27870a5e74c64f04521aa517fea1772bb766f5c9f364d83e24610c7bf7f72c65739adb05b2e9a0ca1230f0
6
+ metadata.gz: 221e2cfb38c4eae38ab6b56250e2d70672c9d1e6883b048f5a6bc807d0996065bf1b8e4a102fd78b6a95a4a4ffcf21dcfd46c64737acd915b3d1b80f9dca273e
7
+ data.tar.gz: 1f04a6b9af22d12a6b310902cdf5761362762a7fcca97c78a2feb17a28ce3199285a8cd1b6e80c56cde10f7fc2983c8598990fa263e5e55656502ad22761dd2e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.16.1 2022-10-13
4
+
5
+ ### Changed
6
+
7
+ - Restored performance of config value reads (direct reader methods as well as aggregate methods like `#values` and `#to_h`) to pre-0.16.0 levels (#149 by @timriley)
8
+
9
+ [Compare v0.16.0...v0.16.1](https://github.com/dry-rb/dry-configurable/compare/v0.16.0...v0.16.1)
10
+
3
11
  ## 0.16.0 2022-10-08
4
12
 
5
13
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/core/constants"
4
+ require "set"
4
5
 
5
6
  require "dry/core/equalizer"
6
7
 
@@ -18,15 +19,27 @@ module Dry
18
19
  # @api private
19
20
  attr_reader :_values
20
21
 
22
+ # @api private
23
+ attr_reader :_configured
24
+ protected :_configured
25
+
21
26
  # @api private
22
27
  def initialize(settings, values: {})
23
28
  @_settings = settings
24
29
  @_values = values
30
+ @_configured = Set.new
31
+ end
32
+
33
+ # @api private
34
+ private def initialize_copy(source)
35
+ super
36
+ @_values = source.__send__(:dup_values)
37
+ @_configured = source._configured.dup
25
38
  end
26
39
 
27
40
  # @api private
28
41
  def dup_for_settings(settings)
29
- self.class.new(settings, values: dup_values)
42
+ dup.tap { |config| config.instance_variable_set(:@_settings, settings) }
30
43
  end
31
44
 
32
45
  # Get config value by a key
@@ -42,10 +55,11 @@ module Dry
42
55
  end
43
56
 
44
57
  _values.fetch(name) {
45
- # When reading values, only capture cloneable (i.e. mutable) values in local state, making
46
- # it easier to determine which values have actually been changed vs just read
58
+ # Mutable settings may be configured after read
59
+ _configured.add(name) if setting.cloneable?
60
+
47
61
  setting.to_value.tap { |value|
48
- _values[name] = value if setting.cloneable?
62
+ _values[name] = value
49
63
  }
50
64
  }
51
65
  end
@@ -64,6 +78,8 @@ module Dry
64
78
  raise ArgumentError, "+#{name}+ is not a setting name"
65
79
  end
66
80
 
81
+ _configured.add(name)
82
+
67
83
  _values[name] = setting.constructor.(value)
68
84
  end
69
85
 
@@ -101,11 +117,11 @@ module Dry
101
117
  #
102
118
  # @api public
103
119
  def configured?(key)
104
- if _settings[key].cloneable? && _values.key?(key)
120
+ if _configured.include?(key) && _settings[key].cloneable?
105
121
  return _values[key] != _settings[key].to_value
106
122
  end
107
123
 
108
- _values.key?(key)
124
+ _configured.include?(key)
109
125
  end
110
126
 
111
127
  # Returns the current config values.
@@ -116,7 +132,10 @@ module Dry
116
132
  #
117
133
  # @api public
118
134
  def values
119
- _settings.to_h { |setting| [setting.name, self[setting.name]] }
135
+ # Ensure all settings are represented in values
136
+ _settings.each { |setting| self[setting.name] unless _values.key?(setting.name) }
137
+
138
+ _values
120
139
  end
121
140
 
122
141
  # Returns config values as a hash, with nested values also converted from {Config} instances
@@ -175,11 +194,6 @@ module Dry
175
194
  dup_hsh[key] = _settings[key].cloneable? ? val.dup : val
176
195
  }
177
196
  end
178
-
179
- def initialize_copy(source)
180
- super
181
- @_values = source.__send__(:dup_values)
182
- end
183
197
  end
184
198
  end
185
199
  end
@@ -24,6 +24,9 @@ module Dry
24
24
  # @api private
25
25
  attr_reader :default
26
26
 
27
+ # @api private
28
+ attr_reader :cloneable
29
+
27
30
  # @api private
28
31
  attr_reader :constructor
29
32
 
@@ -48,6 +51,9 @@ module Dry
48
51
  )
49
52
  @name = name
50
53
  @default = default
54
+ @cloneable = children.any? || options.fetch(:cloneable) {
55
+ Setting.cloneable_value?(default)
56
+ }
51
57
  @constructor = constructor
52
58
  @children = children
53
59
  @options = options
@@ -60,7 +66,7 @@ module Dry
60
66
 
61
67
  # @api private
62
68
  def cloneable?
63
- children.any? || options.fetch(:cloneable) { Setting.cloneable_value?(default) }
69
+ cloneable
64
70
  end
65
71
 
66
72
  # @api private
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  module Configurable
5
5
  # @api public
6
- VERSION = "0.16.0"
6
+ VERSION = "0.16.1"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-configurable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-07 00:00:00.000000000 Z
11
+ date: 2022-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-core
@@ -114,7 +114,7 @@ metadata:
114
114
  changelog_uri: https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md
115
115
  source_code_uri: https://github.com/dry-rb/dry-configurable
116
116
  bug_tracker_uri: https://github.com/dry-rb/dry-configurable/issues
117
- post_install_message:
117
+ post_install_message:
118
118
  rdoc_options: []
119
119
  require_paths:
120
120
  - lib
@@ -129,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.3.7
133
- signing_key:
132
+ rubygems_version: 3.1.6
133
+ signing_key:
134
134
  specification_version: 4
135
135
  summary: A mixin to add configuration functionality to your classes
136
136
  test_files: []