dry-configurable 0.14.0 → 0.15.0

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: 90bd271135f8ccb892c1cf3afc448f92fe50587567725e860de78b4ed58bb57a
4
- data.tar.gz: 8580ad144d2fa3e0189c65a9873282db49c8ddd7d5c349b0f4d6f292e7f675ce
3
+ metadata.gz: b464e3a14e23a75467fc56883a5e222ad96139fee156972e58729607113cba55
4
+ data.tar.gz: 599d39ad241c3a6c17d27dd3ea8be2d94c1821a1c23ca9dea675126ba6c05ca6
5
5
  SHA512:
6
- metadata.gz: b6613b8677ab724316dde1440ff0640021621d48eec1e0ca1125e28dfdb82bfd94800a3bf5d511fc704062dded24de5bd266012c7145028f2d2322a2837ad77c
7
- data.tar.gz: 69a5d08bfbf53bc232ec8f0fb56186576fe1fe5128205d9597b87bccce750bc94256da9cd9644fa94b4e175f6f86911bad99e866f627e06f2386c29fbc89a634
6
+ metadata.gz: 8d306539d687ef4dc2ee1a999008ab3ead0f466cef01cc17b0122bc088d503da4515b906fa1d26449a4c1dd57b82d39cfd2558c4734061025fb6954383364ee3
7
+ data.tar.gz: 421f2b5bc4a89b155d889ee4305183a3f97c42ab74db8cd9c41fecbccbb0f11ff739a4a01afa780da4291bf3404e6ed87c224093ee08f8de706ce46d30b39da8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.15.0 2022-04-21
4
+
5
+
6
+ ### Changed
7
+
8
+ - The `finalize!` method (as class or instance method, depending on whether you extend or include `Dry::Configurable` respectively) now accepts a boolean `freeze_values:` argument, which if true, will recursively freeze all config values in addition to the `config` itself. (#105 by @ojab)
9
+
10
+ ```ruby
11
+ class MyConfigurable
12
+ include Dry::Configurable
13
+
14
+ setting :db, default: "postgre"
15
+ end
16
+
17
+ my_obj = MyConfigurable.new
18
+ my_obj.finalize!(freeze_values: true)
19
+ my_obj.config.db << "sql" # Will raise FrozenError
20
+ ```
21
+ - `Dry::Configurable::Config#update` will set hashes as values for non-nested settings (#131 by @ojab)
22
+
23
+ ```ruby
24
+ class MyConfigurable
25
+ extend Dry::Configurable
26
+
27
+ setting :sslcert, constructor: ->(v) { v&.values_at(:pem, :pass)&.join }
28
+ end
29
+
30
+ MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"})
31
+ MyConfigurable.config.sslcert # => "certqwerty"
32
+ ```
33
+ - `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash` (#133 by @timriley)
34
+
35
+ [Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-configurable/compare/v0.14.0...v0.15.0)
36
+
3
37
  ## 0.14.0 2022-01-14
4
38
 
5
39
 
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![CI Status](https://github.com/dry-rb/dry-configurable/workflows/ci/badge.svg)][actions]
12
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0276a97990e04eb0ac722b3e7f3620b5)][codacy]
13
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0276a97990e04eb0ac722b3e7f3620b5)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=main)][inchpages]
15
15
 
16
16
  ## Links
17
17
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md"
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-configurable"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-configurable/issues"
28
28
 
@@ -50,16 +50,19 @@ module Dry
50
50
 
51
51
  # Update config with new values
52
52
  #
53
- # @param values [Hash] A hash with new values
53
+ # @param values [Hash, #to_hash] A hash with new values
54
54
  #
55
55
  # @return [Config]
56
56
  #
57
57
  # @api public
58
58
  def update(values)
59
59
  values.each do |key, value|
60
- case value
61
- when Hash
62
- self[key].update(value)
60
+ if self[key].is_a?(self.class)
61
+ unless value.respond_to?(:to_hash)
62
+ raise ArgumentError, "#{value.inspect} is not a valid setting value"
63
+ end
64
+
65
+ self[key].update(value.to_hash)
63
66
  else
64
67
  self[key] = value
65
68
  end
@@ -81,8 +84,8 @@ module Dry
81
84
  alias_method :to_h, :values
82
85
 
83
86
  # @api private
84
- def finalize!
85
- _settings.freeze
87
+ def finalize!(freeze_values: false)
88
+ _settings.finalize!(freeze_values: freeze_values)
86
89
  freeze
87
90
  end
88
91
 
@@ -38,9 +38,7 @@ module Dry
38
38
  # Finalize the config and freeze the object
39
39
  #
40
40
  # @api public
41
- def finalize!
42
- return self if frozen?
43
-
41
+ def finalize!(freeze_values: false)
44
42
  super
45
43
  freeze
46
44
  end
@@ -21,10 +21,8 @@ module Dry
21
21
  # @return [Dry::Configurable::Config]
22
22
  #
23
23
  # @api public
24
- def finalize!
25
- return self if config.frozen?
26
-
27
- config.finalize!
24
+ def finalize!(freeze_values: false)
25
+ config.finalize!(freeze_values: freeze_values)
28
26
  self
29
27
  end
30
28
  end
@@ -84,8 +84,12 @@ module Dry
84
84
 
85
85
  # @api private
86
86
  def value
87
- @value ||= evaluate
87
+ return @value if evaluated?
88
+
89
+ @value = constructor[Undefined.coalesce(input, default, nil)]
88
90
  end
91
+ alias_method :evaluate, :value
92
+ private :evaluate
89
93
 
90
94
  # @api private
91
95
  def evaluated?
@@ -102,6 +106,16 @@ module Dry
102
106
  with(input: Undefined)
103
107
  end
104
108
 
109
+ # @api private
110
+ def finalize!(freeze_values: false)
111
+ if value.is_a?(Config)
112
+ value.finalize!(freeze_values: freeze_values)
113
+ elsif freeze_values
114
+ value.freeze
115
+ end
116
+ freeze
117
+ end
118
+
105
119
  # @api private
106
120
  def with(new_opts)
107
121
  self.class.new(name, input: input, default: default, **options, **new_opts)
@@ -149,11 +163,6 @@ module Dry
149
163
  @value = source.value.dup if source.evaluated?
150
164
  end
151
165
  end
152
-
153
- # @api private
154
- def evaluate
155
- @value = constructor[Undefined.coalesce(input, default, nil)]
156
- end
157
166
  end
158
167
  end
159
168
  end
@@ -54,6 +54,12 @@ module Dry
54
54
  self.class.new(map(&:pristine))
55
55
  end
56
56
 
57
+ # @api private
58
+ def finalize!(freeze_values: false)
59
+ each { |element| element.finalize!(freeze_values: freeze_values) }
60
+ freeze
61
+ end
62
+
57
63
  private
58
64
 
59
65
  # @api private
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  module Configurable
5
5
  # @api public
6
- VERSION = "0.14.0"
6
+ VERSION = "0.15.0"
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.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -111,7 +111,7 @@ licenses:
111
111
  - MIT
112
112
  metadata:
113
113
  allowed_push_host: https://rubygems.org
114
- changelog_uri: https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md
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
117
  post_install_message: