dry-configurable 0.12.0 → 0.12.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: 102cb0a4fe42ebde6835f50b7e75826dbc4b98c78cca9fcee5c5863c1c47651f
4
- data.tar.gz: f5da17ecfb79edfa42c0d6c9a0d05d3e4cce2297533ec3151afafc9e6d4151b3
3
+ metadata.gz: 38b75c91290021054add38bdd9e3313f17aa133e219330a9b02a83227abd101c
4
+ data.tar.gz: 4b808bd3880c35e2e80a702e4577f2b2da35ef2b31667f4314accc3cf0c20470
5
5
  SHA512:
6
- metadata.gz: 7d6dac8ebf7eddf6eb8b61da5cef0a434769270fc5ad2ab13ea7a4c5d093c047681b1bc85da4ba09190cfcf17ef023293dc4ccdb2f8dd2ac7eae19dbb4c69706
7
- data.tar.gz: be0be051c79c2ef527d678cb9f839d6cabf40669b19864d38a735fe428a277068504897bd289baf69e0da26f470e35e0c2e73bc99f62dd16286fa7148a35572c
6
+ metadata.gz: efdd98ed5f60acf8090296954942f01c21702c29fa60c1edea21e0fbbb185955963b268191cb042ee33cc4651f4350419e7cbc2b7125c36103dce2733d137fa4
7
+ data.tar.gz: 21d278a4f9f4a90d530145408585c30e004ce2830d5777a408bd9ea83bdfd5cba2ce58f1a1ca46f1212d0e8d5967891a25467f39e59a8af20291cf5ca1beff3f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.12.1 2021-02-15
4
+
5
+
6
+ ### Added
7
+
8
+ - Settings may be specified with a `cloneable` option, e.g.
9
+
10
+ ```ruby
11
+ setting :component_dirs, Configuration::ComponentDirs.new, cloneable: true
12
+ ```
13
+
14
+ This change makes it possible to provide “rich” config values that carry their own
15
+ configuration interface.
16
+
17
+ In the above example, `ComponentDirs` could provide its own API for adding component
18
+ dirs and configuring aspects of their behavior at the same time. By being passed to
19
+ the setting along with `cloneable: true`, dry-configurable will ensure the setting's
20
+ values are cloned along with the setting at all the appropriate times.
21
+
22
+ A custom cloneable setting value should provide its own `#initialize_copy` (used by
23
+ `Object#dup`) with the appropriate logic. (@timriley in #102)
24
+
25
+ ### Fixed
26
+
27
+ - Only `#initialize` instance method is prepended, leaving the rest of the instance
28
+ methods to be included as normal again. This allows classes including
29
+ `Dry::Configurable` to override instance methods with their own methods as required
30
+ (@adam12 in #103)
31
+
32
+
33
+ [Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-configurable/compare/v0.12.0...v0.12.1)
34
+
3
35
  ## 0.12.0 2020-12-26
4
36
 
5
37
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2021 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -57,7 +57,8 @@ module Dry
57
57
  super
58
58
  klass.class_eval do
59
59
  extend(ClassMethods)
60
- prepend(InstanceMethods)
60
+ include(InstanceMethods)
61
+ prepend(Initializer)
61
62
 
62
63
  class << self
63
64
  undef :config
@@ -5,6 +5,18 @@ require 'dry/configurable/methods'
5
5
 
6
6
  module Dry
7
7
  module Configurable
8
+ # Initializer method which is prepended when `Dry::Configurable`
9
+ # is included in a class
10
+ #
11
+ # @api private
12
+ module Initializer
13
+ # @api private
14
+ def initialize(*)
15
+ @config = Config.new(self.class._settings.dup)
16
+ super
17
+ end
18
+ end
19
+
8
20
  # Instance-level API when `Dry::Configurable` is included in a class
9
21
  #
10
22
  # @api public
@@ -18,12 +30,6 @@ module Dry
18
30
  # @api public
19
31
  attr_reader :config
20
32
 
21
- # @api private
22
- def initialize(*)
23
- @config = Config.new(self.class._settings.dup)
24
- super
25
- end
26
-
27
33
  # Finalize the config and freeze the object
28
34
  #
29
35
  # @api public
@@ -15,11 +15,11 @@ module Dry
15
15
  class Setting
16
16
  include Dry::Equalizer(:name, :value, :options, inspect: false)
17
17
 
18
- OPTIONS = %i[input default reader constructor settings].freeze
18
+ OPTIONS = %i[input default reader constructor cloneable settings].freeze
19
19
 
20
20
  DEFAULT_CONSTRUCTOR = -> v { v }.freeze
21
21
 
22
- CLONABLE_VALUE_TYPES = [Array, Hash, Set, Config].freeze
22
+ CLONEABLE_VALUE_TYPES = [Array, Hash, Set, Config].freeze
23
23
 
24
24
  # @api private
25
25
  attr_reader :name
@@ -54,8 +54,8 @@ module Dry
54
54
  end
55
55
 
56
56
  # @api private
57
- def self.clonable_value?(value)
58
- CLONABLE_VALUE_TYPES.any? { |type| value.is_a?(type) }
57
+ def self.cloneable_value?(value)
58
+ CLONEABLE_VALUE_TYPES.any? { |type| value.is_a?(type) }
59
59
  end
60
60
 
61
61
  # @api private
@@ -114,15 +114,32 @@ module Dry
114
114
  writer_name.equal?(meth)
115
115
  end
116
116
 
117
+ # @api private
118
+ def cloneable?
119
+ if options.key?(:cloneable)
120
+ # Return cloneable option if explicitly set
121
+ options[:cloneable]
122
+ else
123
+ # Otherwise, infer cloneable from any of the input, default, or value
124
+ Setting.cloneable_value?(input) || Setting.cloneable_value?(default) || (
125
+ evaluated? && Setting.cloneable_value?(value)
126
+ )
127
+ end
128
+ end
129
+
117
130
  private
118
131
 
119
132
  # @api private
120
133
  def initialize_copy(source)
121
134
  super
122
- @input = source.input.dup if Setting.clonable_value?(source.input)
123
- @default = source.default.dup if Setting.clonable_value?(source.default)
124
- @value = source.value.dup if source.evaluated? && Setting.clonable_value?(source.value)
135
+
125
136
  @options = source.options.dup
137
+
138
+ if source.cloneable?
139
+ @input = source.input.dup
140
+ @default = source.default.dup
141
+ @value = source.value.dup if source.evaluated?
142
+ end
126
143
  end
127
144
 
128
145
  # @api private
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  module Configurable
5
5
  # @api public
6
- VERSION = '0.12.0'
6
+ VERSION = '0.12.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.12.0
4
+ version: 0.12.1
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-12-26 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby