dry-configurable 0.11.0 → 0.11.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d220ee0a9d75b6b400a98b8165b32f9c3fe3fbfdc4661f36e8a99a6a36181cb7
4
- data.tar.gz: 3c22814973a66b5ea08efaa14c6c8dc2130b7a8c20e48167e400aa51e66426e3
3
+ metadata.gz: f0faa56dea70f112144295394747175b526e116cdfd09d3ccfa047b85dd06b11
4
+ data.tar.gz: 48fc6304ef41ea05076765bbe8f7286e90ed69ee54b388650d3654b74b4ebfda
5
5
  SHA512:
6
- metadata.gz: 44819f0abbc69555c660df2cf1e777bd0a6ca9bcccc9fbbd9c1198983e2739e47530527f7d07b737432a4429fe1243d28d62625992bb76f91e1437bab441eb42
7
- data.tar.gz: 28001d7d843d4e70bbcc4a57332400b868fd385345b8a5977b82c713fc2b9f21f4a5e5746fee630e8f6d83990144943b7b7b1e604291a91096fd25971982c91e
6
+ metadata.gz: 9c6c284433350053c27e745a8bcb0a0c000c22d4fe684c39eeb20340d026b764f8d80ee155a30ba88af66f4e9ba1022e1572accfa5aff4657b463978534d964e
7
+ data.tar.gz: ed4d650fb3f2d7f92d05bad9575c452bf67138489a734e91ccc4fb6d9fa5932a6dee72430a84c7b2994b8d28bb42a6d7c4dda8e5b82e9ce51ac588a0888f1b2b
data/CHANGELOG.md CHANGED
@@ -1,4 +1,58 @@
1
- ## unreleased
1
+ ## 0.11.5 2020-03-23
2
+
3
+
4
+ ### Fixed
5
+
6
+ - When settings are copied or cloned, unevaluated values will no longer be copied. This prevents unintended crashes when settings have constructors expecting a certain type of value, but that value is yet to be provided (Fixed via #87) (@timriley)
7
+
8
+
9
+ [Compare v0.11.4...v0.11.5](https://github.com/dry-rb/dry-configurable/compare/v0.11.4...v0.11.5)
10
+
11
+ ## 0.11.4 2020-03-16
12
+
13
+
14
+ ### Fixed
15
+
16
+ - `Config#update` returns `self` again (issue #60 fixed via #92) (@solnic)
17
+
18
+ ### Changed
19
+
20
+ - `Setting#inspect` no longer uses its value - this could cause crashes when inspecting settings that are yet to have a value applied (e.g. when they have a constructor that expects a value to be present) (@timriley)
21
+
22
+ [Compare v0.11.3...v0.11.4](https://github.com/dry-rb/dry-configurable/compare/v0.11.3...v0.11.4)
23
+
24
+ ## 0.11.3 2020-02-22
25
+
26
+
27
+ ### Fixed
28
+
29
+ - Retrieving settings by a string name works again (issue #82) (@waiting-for-dev)
30
+
31
+
32
+ [Compare v0.11.2...v0.11.3](https://github.com/dry-rb/dry-configurable/compare/v0.11.2...v0.11.3)
33
+
34
+ ## 0.11.2 2020-02-20
35
+
36
+
37
+ ### Fixed
38
+
39
+ - Warning about redefined `Setting#value` is gone (@solnic)
40
+
41
+
42
+ [Compare v0.11.1...v0.11.2](https://github.com/dry-rb/dry-configurable/compare/v0.11.1...v0.11.2)
43
+
44
+ ## 0.11.1 2020-02-18
45
+
46
+
47
+ ### Fixed
48
+
49
+ - You can use `:settings` as a config key again (issue #80) (@solnic)
50
+ - Setting value is lazy-evaluated now, which fixes some cases where a constructor could crash with a `nil` value (@solnic)
51
+
52
+
53
+ [Compare v0.11.0...v0.11.1](https://github.com/dry-rb/dry-configurable/compare/v0.11.0...v0.11.1)
54
+
55
+ ## 0.11.0 2020-02-15
2
56
 
3
57
  Complete rewrite of the library while keeping the public API intact. See #78 for a detailed overview.
4
58
 
@@ -8,7 +62,7 @@ Complete rewrite of the library while keeping the public API intact. See #78 for
8
62
  - (internal) New low-level Setting and Config API (@solnic)
9
63
  - (internal) `config` objects use method_missing now (@solnic)
10
64
 
11
- [Compare v0.10.0...master](https://github.com/dry-rb/dry-configurable/compare/v0.10.0...master)
65
+ [Compare v0.10.0...v0.11.0](https://github.com/dry-rb/dry-configurable/compare/v0.10.0...v0.11.0)
12
66
 
13
67
  ## 0.10.0 2020-01-31
14
68
 
@@ -16,7 +16,7 @@ module Dry
16
16
  def inherited(klass)
17
17
  super
18
18
 
19
- parent_settings = (respond_to?(:config) ? config.settings : _settings)
19
+ parent_settings = (respond_to?(:config) ? config._settings : _settings)
20
20
 
21
21
  klass.instance_variable_set('@_settings', parent_settings)
22
22
  end
@@ -16,15 +16,15 @@ module Dry
16
16
  include Dry::Equalizer(:values)
17
17
 
18
18
  # @api private
19
- attr_reader :settings
19
+ attr_reader :_settings
20
20
 
21
21
  # @api private
22
- attr_reader :resolved
22
+ attr_reader :_resolved
23
23
 
24
24
  # @api private
25
25
  def initialize(settings)
26
- @settings = settings.dup
27
- @resolved = Concurrent::Map.new
26
+ @_settings = settings.dup
27
+ @_resolved = Concurrent::Map.new
28
28
  end
29
29
 
30
30
  # Get config value by a key
@@ -33,9 +33,10 @@ module Dry
33
33
  #
34
34
  # @return Config value
35
35
  def [](name)
36
- raise ArgumentError, "+#{name}+ is not a setting name" unless settings.key?(name)
36
+ name = name.to_sym
37
+ raise ArgumentError, "+#{name}+ is not a setting name" unless _settings.key?(name)
37
38
 
38
- settings[name].value
39
+ _settings[name].value
39
40
  end
40
41
 
41
42
  # Set config value.
@@ -49,7 +50,7 @@ module Dry
49
50
 
50
51
  # Update config with new values
51
52
  #
52
- # @param [Hash] A hash with new values
53
+ # @param values [Hash] A hash with new values
53
54
  #
54
55
  # @return [Config]
55
56
  #
@@ -63,6 +64,7 @@ module Dry
63
64
  self[key] = value
64
65
  end
65
66
  end
67
+ self
66
68
  end
67
69
 
68
70
  # Dump config into a hash
@@ -71,7 +73,7 @@ module Dry
71
73
  #
72
74
  # @api public
73
75
  def values
74
- settings
76
+ _settings
75
77
  .map { |setting| [setting.name, setting.value] }
76
78
  .map { |key, value| [key, value.is_a?(self.class) ? value.to_h : value] }
77
79
  .to_h
@@ -81,32 +83,32 @@ module Dry
81
83
 
82
84
  # @api private
83
85
  def finalize!
84
- settings.freeze
86
+ _settings.freeze
85
87
  freeze
86
88
  end
87
89
 
88
90
  # @api private
89
91
  def pristine
90
- self.class.new(settings.pristine)
92
+ self.class.new(_settings.pristine)
91
93
  end
92
94
 
93
95
  # @api private
94
96
  def respond_to_missing?(meth, include_private = false)
95
- super || settings.key?(resolve(meth))
97
+ super || _settings.key?(resolve(meth))
96
98
  end
97
99
 
98
100
  private
99
101
 
100
102
  # @api private
101
103
  def method_missing(meth, *args)
102
- setting = settings[resolve(meth)]
104
+ setting = _settings[resolve(meth)]
103
105
 
104
106
  super unless setting
105
107
 
106
108
  if setting.writer?(meth)
107
109
  raise FrozenConfig, 'Cannot modify frozen config' if frozen?
108
110
 
109
- settings << setting.with(input: args[0])
111
+ _settings << setting.with(input: args[0])
110
112
  else
111
113
  setting.value
112
114
  end
@@ -114,13 +116,13 @@ module Dry
114
116
 
115
117
  # @api private
116
118
  def resolve(meth)
117
- resolved.fetch(meth) { resolved[meth] = meth.to_s.tr('=', '').to_sym }
119
+ _resolved.fetch(meth) { _resolved[meth] = meth.to_s.tr('=', '').to_sym }
118
120
  end
119
121
 
120
122
  # @api private
121
123
  def initialize_copy(source)
122
124
  super
123
- @settings = source.settings.dup
125
+ @_settings = source._settings.dup
124
126
  end
125
127
  end
126
128
  end
@@ -43,7 +43,7 @@ module Dry
43
43
 
44
44
  default, opts = args
45
45
 
46
- node = [:setting, [name, default, opts == default ? EMPTY_HASH : opts]]
46
+ node = [:setting, [name.to_sym, default, opts == default ? EMPTY_HASH : opts]]
47
47
 
48
48
  if block
49
49
  if block.arity.zero?
@@ -13,7 +13,7 @@ module Dry
13
13
  #
14
14
  # @api private
15
15
  class Setting
16
- include Dry::Equalizer(:name, :value, :options)
16
+ include Dry::Equalizer(:name, :value, :options, inspect: false)
17
17
 
18
18
  OPTIONS = %i[input default reader constructor settings].freeze
19
19
 
@@ -33,9 +33,6 @@ module Dry
33
33
  # @api private
34
34
  attr_reader :default
35
35
 
36
- # @api private
37
- attr_reader :value
38
-
39
36
  # @api private
40
37
  attr_reader :options
41
38
 
@@ -63,7 +60,21 @@ module Dry
63
60
  @input = input.equal?(Undefined) ? default : input
64
61
  @default = default
65
62
  @options = options
66
- set!
63
+ end
64
+
65
+ # @api private
66
+ def input_defined?
67
+ !input.equal?(Undefined)
68
+ end
69
+
70
+ # @api private
71
+ def value
72
+ @value ||= evaluate
73
+ end
74
+
75
+ # @api private
76
+ def evaluated?
77
+ instance_variable_defined?(:@value)
67
78
  end
68
79
 
69
80
  # @api private
@@ -106,12 +117,12 @@ module Dry
106
117
  # @api private
107
118
  def initialize_copy(source)
108
119
  super
109
- @value = source.value.dup if source.clonable_value?
120
+ @value = source.value.dup if source.input_defined? && source.clonable_value?
110
121
  @options = source.options.dup
111
122
  end
112
123
 
113
124
  # @api private
114
- def set!
125
+ def evaluate
115
126
  @value = constructor[input.equal?(Undefined) ? nil : input]
116
127
  end
117
128
  end
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  module Configurable
5
5
  # @api public
6
- VERSION = '0.11.0'
6
+ VERSION = '0.11.5'
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.11.0
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-15 00:00:00.000000000 Z
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby