From 2416cc89b70a05a2e1a7a55581668228215aa2b2 Mon Sep 17 00:00:00 2001 From: Piotr Solnica Date: Thu, 8 Jul 2021 17:16:38 +0200 Subject: [PATCH 01/82] Rename ivar used for __config_dsl__ This was clashing with rom mapper/transformer --- lib/dry/configurable/class_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dry/configurable/class_methods.rb b/lib/dry/configurable/class_methods.rb index 8edad27..6a7e028 100644 --- a/lib/dry/configurable/class_methods.rb +++ b/lib/dry/configurable/class_methods.rb @@ -76,7 +76,7 @@ module Dry # @api private def __config_dsl__ - @dsl ||= DSL.new + @__config_dsl__ ||= DSL.new end # @api private From afa21dc230a0c95492682cffb527a6203a48eb7e Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 08:26:25 +0000 Subject: [PATCH 02/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index f33872c..46b44ec 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -174,6 +174,9 @@ Style/MultipleComparison: Style/Next: Enabled: false +Style/AccessorGrouping: + Enabled: false + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From 4a7f2db42425d40ba01cc45bcdbed40a9ef30d70 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 08:50:50 +0000 Subject: [PATCH 03/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 46b44ec..b2a2e4d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -67,9 +67,7 @@ Naming/MethodName: Enabled: false Naming/MethodParameterName: - Enabled: true - Exclude: - - "spec/**/*.rb" + Enabled: false Naming/MemoizedInstanceVariableName: Enabled: false @@ -177,10 +175,21 @@ Style/Next: Style/AccessorGrouping: Enabled: false +Style/EmptyLiteral: + Enabled: false + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" +Lint/Debugger: + Exclude: + - "bin/console" + +Lint/BinaryOperatorWithIdenticalOperands: + Exclude: + - "spec/**/*.rb" + Metrics/ParameterLists: Exclude: - "spec/**/*.rb" @@ -189,6 +198,14 @@ Lint/EmptyBlock: Exclude: - "spec/**/*.rb" +Lint/UselessMethodDefinition: + Exclude: + - "spec/**/*.rb" + Naming/ConstantName: Exclude: - "spec/**/*.rb" + +Naming/VariableNumber: + Exclude: + - "spec/**/*.rb" From 068ee688e1b582a2dd8eef58aa19d3a75289fd63 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 11:17:11 +0000 Subject: [PATCH 04/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index b2a2e4d..dc6094e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -202,6 +202,9 @@ Lint/UselessMethodDefinition: Exclude: - "spec/**/*.rb" +Lint/SelfAssignment: + Enabled: false + Naming/ConstantName: Exclude: - "spec/**/*.rb" From 51e106a2919726dea405f242ad2c8f322c885d9d Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 12:47:39 +0000 Subject: [PATCH 05/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index dc6094e..bff36e3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -178,6 +178,10 @@ Style/AccessorGrouping: Style/EmptyLiteral: Enabled: false +Style/Semicolon: + Exclude: + - "spec/**/*.rb" + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From be61706f8dabdcec65ee76e88bab80d48a5503fe Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 13:20:09 +0000 Subject: [PATCH 06/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index bff36e3..868ea5a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -182,6 +182,10 @@ Style/Semicolon: Exclude: - "spec/**/*.rb" +Style/CaseEquality: + Exclude: + - "dry/monads/**/*.rb" + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From 50484452003249ef4fc3ee7dd7b4237b40c9f57a Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 18 Jul 2021 13:23:24 +0000 Subject: [PATCH 07/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 868ea5a..5eefc1a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -184,7 +184,7 @@ Style/Semicolon: Style/CaseEquality: Exclude: - - "dry/monads/**/*.rb" + - "lib/dry/monads/**/*.rb" Lint/UnusedBlockArgument: Exclude: From caf27acea76893e77e792b6ba87226642b7626b0 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 19 Jul 2021 07:21:32 +0000 Subject: [PATCH 08/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 5eefc1a..6c11d98 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -220,3 +220,6 @@ Naming/ConstantName: Naming/VariableNumber: Exclude: - "spec/**/*.rb" + +Naming/BinaryOperatorParameterName: + Enabled: false From 16c7a1b706cfc3941689fb52bf39013840e8ebaa Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 19 Jul 2021 12:13:46 +0000 Subject: [PATCH 09/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea99e34..edf7e41 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # dry-configurable [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat] [![Gem Version](https://badge.fury.io/rb/dry-configurable.svg)][gem] -[![CI Status](https://github.com/dry-rb/dry-configurable/workflows/ci/badge.svg)][actions] +[![CI Status](https://github.com/dry-rb/dry-configurable/workflows/CI/badge.svg)][actions] [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0276a97990e04eb0ac722b3e7f3620b5)][codacy] [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0276a97990e04eb0ac722b3e7f3620b5)][codacy] [![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=master)][inchpages] From 826d26da9c71a0fd6ebce6644b10ed84ac2c2f80 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 17:53:39 +0000 Subject: [PATCH 10/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 6c11d98..ff6e30f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -185,6 +185,8 @@ Style/Semicolon: Style/CaseEquality: Exclude: - "lib/dry/monads/**/*.rb" + - "lib/dry/struct/**/*.rb" + - "lib/dry/types/**/*.rb" Lint/UnusedBlockArgument: Exclude: From 1a13110714ae3ad666ec6c5c5241d609523d09dd Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 17:58:21 +0000 Subject: [PATCH 11/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index ff6e30f..3d2c4f8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -187,6 +187,7 @@ Style/CaseEquality: - "lib/dry/monads/**/*.rb" - "lib/dry/struct/**/*.rb" - "lib/dry/types/**/*.rb" + - "spec/**/*.rb" Lint/UnusedBlockArgument: Exclude: From 8585068de3fb0fb762aee1b53125d57a310aeb43 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 18:36:47 +0000 Subject: [PATCH 12/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 3d2c4f8..5abf92f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -216,6 +216,9 @@ Lint/UselessMethodDefinition: Lint/SelfAssignment: Enabled: false +Lint/EmptyClass: + Enabled: false + Naming/ConstantName: Exclude: - "spec/**/*.rb" From 00e37bd6c99e7bc68a2085df4ea20b724e647373 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 19:13:29 +0000 Subject: [PATCH 13/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 5abf92f..b0fee51 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -182,6 +182,10 @@ Style/Semicolon: Exclude: - "spec/**/*.rb" +Style/HashAsLastArrayItem: + Exclude: + - "spec/**/*.rb" + Style/CaseEquality: Exclude: - "lib/dry/monads/**/*.rb" From 4156b024ca1b885788df1af50302dc529bec72f1 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 19:20:54 +0000 Subject: [PATCH 14/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index b0fee51..9bb9567 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ AllCops: TargetRubyVersion: 2.6 NewCops: enable Exclude: + - bechmarks/*.rb - spec/support/coverage.rb - spec/support/warnings.rb - spec/support/rspec_options.rb From d27fb0c29ee66ee5080cb296bfe4d5c88e4f811c Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 19:24:29 +0000 Subject: [PATCH 15/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9bb9567..84165a8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,6 +57,10 @@ Lint/SuppressedException: Exclude: - "spec/spec_helper.rb" +Lint/LiteralAsCondition: + Exclude: + - "spec/**/*.rb" + Naming/PredicateName: Enabled: false From 1216ba3815239f1d3c4efda9cb6faac893de4faf Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 19:44:19 +0000 Subject: [PATCH 16/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 84165a8..f5a9514 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ AllCops: TargetRubyVersion: 2.6 NewCops: enable Exclude: - - bechmarks/*.rb + - benchmarks/*.rb - spec/support/coverage.rb - spec/support/warnings.rb - spec/support/rspec_options.rb From e455acc0887e7dec7e2557afb107b01e74a8bb84 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 20:52:55 +0000 Subject: [PATCH 17/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index f5a9514..9f72d58 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -198,6 +198,13 @@ Style/CaseEquality: - "lib/dry/types/**/*.rb" - "spec/**/*.rb" +Style/ExplicitBlockArgument: + Exclude: + - "lib/dry/types/**/*.rb" + +Style/CombinableLoops: + Enabled: false + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From f44ea91a79f232c591f1d75de857d05dc1f29748 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 21 Jul 2021 21:04:25 +0000 Subject: [PATCH 18/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9f72d58..70e5787 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -205,6 +205,9 @@ Style/ExplicitBlockArgument: Style/CombinableLoops: Enabled: false +Style/EmptyElse: + Enabled: false + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From 9a6fbbd32a782cb5965a64600bcfe9a1ae749c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Wed, 11 Aug 2021 09:16:39 +0200 Subject: [PATCH 19/82] Fix test suite after change in deprecation's uplevel value in dry-core (#119) After the legit change made at dry-rb/dry-core#56, the test suite here was failing because of a wrong assumption made before: our tests are calling from the DSL object itself in contrast to the class extending it. I.e., we can't rely on the default value of the `uplevel` parameter as we're skipping one stack. References #115 --- spec/unit/dry/configurable/dsl_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/dry/configurable/dsl_spec.rb b/spec/unit/dry/configurable/dsl_spec.rb index bc93f81..ac0ec74 100644 --- a/spec/unit/dry/configurable/dsl_spec.rb +++ b/spec/unit/dry/configurable/dsl_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Dry::Configurable::DSL do expect(setting.name).to be(:user) expect(setting.value).to eql("root") logger.rewind - expect(logger.string).to match(/#{FileUtils.pwd}.*default value as positional argument to settings is deprecated/) + expect(logger.string).to match(/default value as positional argument to settings is deprecated/) end it "compiles a setting with a reader set" do @@ -71,7 +71,7 @@ RSpec.describe Dry::Configurable::DSL do expect(setting.name).to be(:dsn) expect(setting.value).to eql("jdbc:sqlite") logger.rewind - expect(logger.string).to match(/#{FileUtils.pwd}.*constructor as a block is deprecated/) + expect(logger.string).to match(/constructor as a block is deprecated/) end it "compiles a nested list of settings" do From 793a2035187fab5db883fdd4d4de17884789b4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Wed, 11 Aug 2021 15:16:59 +0200 Subject: [PATCH 20/82] Update docs with `default:` & `constructor:` kwargs (#123) See #111 & #112 --- docsite/source/index.html.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docsite/source/index.html.md b/docsite/source/index.html.md index 6efeca8..8735626 100644 --- a/docsite/source/index.html.md +++ b/docsite/source/index.html.md @@ -24,17 +24,17 @@ class App # Pass a block for nested configuration (works to any depth) setting :database do # Can pass a default value - setting :dsn, 'sqlite:memory' + setting :dsn, default: 'sqlite:memory' end # Defaults to nil if no default value is given setting :adapter # Construct values - setting(:path, 'test') { |value| Pathname(value) } + setting :path, default: 'test', constructor: proc { |value| Pathname(value) } # Passing the reader option as true will create attr_reader method for the class setting :pool, 5, reader: true # Passing the reader attributes works with nested configuration setting :uploader, reader: true do - setting :bucket, 'dev' + setting :bucket, default: 'dev' end end From 0f3675c8d8caf5513dde67f5211acfc2a9517176 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 6 Aug 2021 14:34:26 +1000 Subject: [PATCH 21/82] Update DSL#setting method docs This isn't a public method to the users of dry-configurable --- lib/dry/configurable/dsl.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dry/configurable/dsl.rb b/lib/dry/configurable/dsl.rb index db7a485..53184a2 100644 --- a/lib/dry/configurable/dsl.rb +++ b/lib/dry/configurable/dsl.rb @@ -27,10 +27,10 @@ module Dry instance_exec(&block) if block end - # Register a new setting node and compile it into a setting object + # Registers a new setting node and compile it into a setting object # # @see ClassMethods.setting - # @api public + # @api private # @return Setting def setting(name, default = Undefined, **options, &block) unless VALID_NAME.match?(name.to_s) From 66a073446f0b9ce4bed6db4a3ba7cc10d762af23 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 6 Aug 2021 00:18:03 +1000 Subject: [PATCH 22/82] Properly deprecate hash defaults in Ruby 2.6/2.7 --- lib/dry/configurable/dsl.rb | 73 +++++++++++++++++++++++++- spec/unit/dry/configurable/dsl_spec.rb | 45 ++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/lib/dry/configurable/dsl.rb b/lib/dry/configurable/dsl.rb index 53184a2..61058d7 100644 --- a/lib/dry/configurable/dsl.rb +++ b/lib/dry/configurable/dsl.rb @@ -32,7 +32,7 @@ module Dry # @see ClassMethods.setting # @api private # @return Setting - def setting(name, default = Undefined, **options, &block) + def setting(name, default = Undefined, **options, &block) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity unless VALID_NAME.match?(name.to_s) raise ArgumentError, "#{name} is not a valid setting name" end @@ -47,6 +47,70 @@ module Dry options = options.merge(default: default) end + if RUBY_VERSION < "3.0" && + default == Undefined && + (valid_opts, invalid_opts = valid_and_invalid_options(options)) && + invalid_opts.any? && + valid_opts.none? + # In Ruby 2.6 and 2.7, when a hash is given as the second positional argument + # (i.e. the hash is intended to be the setting's default value), and there are + # no other keyword arguments given, the hash is assigned to the `options` + # variable instead of `default`. + # + # For example, for this setting: + # + # setting :hash_setting, {my_hash: true} + # + # We'll have a `default` of `Undefined` and an `options` of `{my_hash: true}` + # + # If any additional keyword arguments are provided, e.g.: + # + # setting :hash_setting, {my_hash: true}, reader: true + # + # Then we'll have a `default` of `{my_hash: true}` and an `options` of `{reader: + # true}`, which is what we want. + # + # To work around that first case and ensure our (deprecated) backwards + # compatibility holds for Ruby 2.6 and 2.7, we extract all invalid options from + # `options`, and if there are no remaining valid options (i.e. if there were no + # keyword arguments given), then we can infer the invalid options to be a + # default hash value for the setting. + # + # This approach also preserves the behavior of raising an ArgumentError when a + # distinct hash is _not_ intentionally provided as the second positional + # argument (i.e. it's not enclosed in braces), and instead invalid keyword + # arguments are given alongside valid ones. So this setting: + # + # setting :some_setting, invalid_option: true, reader: true + # + # Would raise an ArgumentError as expected. + # + # However, the one case we can't catch here is when invalid options are supplied + # without hash literal braces, but there are no other keyword arguments + # supplied. In this case, a setting like: + # + # setting :hash_setting, my_hash: true + # + # Is parsed identically to the first case described above: + # + # setting :hash_setting, {my_hash: true} + # + # So in both of these cases, the default value will become `{my_hash: true}`. We + # consider this unlikely to be a problem in practice, since users are not likely + # to be providing invalid options to `setting` and expecting them to be ignored. + # Additionally, the deprecation messages will make the new behavior obvious, and + # encourage the users to upgrade their setting definitions. + + Dry::Core::Deprecations.announce( + "default value as positional argument to settings", + "Provide a `default:` keyword argument instead", + tag: "dry-configurable", + uplevel: 2 + ) + + options = {default: invalid_opts} + end + if block && !block.arity.zero? Dry::Core::Deprecations.announce( "passing a constructor as a block", @@ -77,8 +141,15 @@ module Dry return if options.none? invalid_keys = options.keys - Setting::OPTIONS + raise ArgumentError, "Invalid options: #{invalid_keys.inspect}" unless invalid_keys.empty? end + + # Returns a tuple of valid and invalid options hashes derived from the options hash + # given to the setting + def valid_and_invalid_options(options) + options.partition { |k, _| Setting::OPTIONS.include?(k) }.map(&:to_h) + end end end end diff --git a/spec/unit/dry/configurable/dsl_spec.rb b/spec/unit/dry/configurable/dsl_spec.rb index ac0ec74..c2ddeb9 100644 --- a/spec/unit/dry/configurable/dsl_spec.rb +++ b/spec/unit/dry/configurable/dsl_spec.rb @@ -32,6 +32,51 @@ RSpec.describe Dry::Configurable::DSL do expect(logger.string).to match(/default value as positional argument to settings is deprecated/) end + it "compiles but deprecates giving a defalt hash value as a positional argument (without any keyword args)" do + # This test is necessary for behavior specific to Ruby 2.6 and 2.7 + + logger = StringIO.new + Dry::Core::Deprecations.set_logger!(logger) + + setting = dsl.setting :default_options, {foo: "bar"} + + expect(setting.name).to be(:default_options) + expect(setting.value).to eq(foo: "bar") + logger.rewind + expect(logger.string).to match(/default value as positional argument to settings is deprecated/) + + if RUBY_VERSION < "3.0" + logger = StringIO.new + Dry::Core::Deprecations.set_logger!(logger) + + setting = dsl.setting :default_options, foo: "bar" + + expect(setting.name).to be(:default_options) + expect(setting.value).to eq(foo: "bar") + logger.rewind + expect(logger.string).to match(/default value as positional argument to settings is deprecated/) + end + end + + it "compiles but deprecates giving a defalt hash value as a positional argument (with keyword args) " do + # This test is necessary for behavior specific to Ruby 2.6 and 2.7 + + logger = StringIO.new + Dry::Core::Deprecations.set_logger!(logger) + setting = dsl.setting :default_options, {foo: "bar"}, reader: true + + expect(setting.name).to be(:default_options) + expect(setting.value).to eq(foo: "bar") + logger.rewind + expect(logger.string).to match(/default value as positional argument to settings is deprecated/) + end + + it "does not infer a default hash value when non-valid keyword arguments are mixed in with valid keyword arguments" do + # This test is necessary for behavior specific to Ruby 2.6 and 2.7 + + expect { dsl.setting :default_options, foo: "bar", reader: true }.to raise_error ArgumentError, "Invalid options: [:foo]" + end + it "compiles a setting with a reader set" do setting = dsl.setting(:dsn, default: "sqlite", reader: true) From b84b85c0cd3e57239185070948936547b93ea92f Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Mon, 30 Aug 2021 22:22:53 +1000 Subject: [PATCH 23/82] Add flags to control deprecation notices --- lib/dry/configurable/dsl.rb | 47 +++++++++++++++----------- lib/dry/configurable/flags.rb | 19 +++++++++++ spec/unit/dry/configurable/dsl_spec.rb | 33 +++++++++++++++++- 3 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 lib/dry/configurable/flags.rb diff --git a/lib/dry/configurable/dsl.rb b/lib/dry/configurable/dsl.rb index 61058d7..34c7d07 100644 --- a/lib/dry/configurable/dsl.rb +++ b/lib/dry/configurable/dsl.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "dry/configurable/constants" +require "dry/configurable/flags" require "dry/configurable/setting" require "dry/configurable/settings" require "dry/configurable/compiler" @@ -32,18 +33,21 @@ module Dry # @see ClassMethods.setting # @api private # @return Setting - def setting(name, default = Undefined, **options, &block) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity + def setting(name, default = Undefined, **options, &block) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity unless VALID_NAME.match?(name.to_s) raise ArgumentError, "#{name} is not a valid setting name" end if default != Undefined - Dry::Core::Deprecations.announce( - "default value as positional argument to settings", - "Provide a `default:` keyword argument instead", - tag: "dry-configurable", - uplevel: 2 - ) + if Dry::Configurable.warn_on_setting_positional_default + Dry::Core::Deprecations.announce( + "default value as positional argument to settings", + "Provide a `default:` keyword argument instead", + tag: "dry-configurable", + uplevel: 2 + ) + end + options = options.merge(default: default) end @@ -101,23 +105,28 @@ module Dry # Additionally, the deprecation messages will make the new behavior obvious, and # encourage the users to upgrade their setting definitions. - Dry::Core::Deprecations.announce( - "default value as positional argument to settings", - "Provide a `default:` keyword argument instead", - tag: "dry-configurable", - uplevel: 2 - ) + if Dry::Configurable.warn_on_setting_positional_default + Dry::Core::Deprecations.announce( + "default value as positional argument to settings", + "Provide a `default:` keyword argument instead", + tag: "dry-configurable", + uplevel: 2 + ) + end options = {default: invalid_opts} end if block && !block.arity.zero? - Dry::Core::Deprecations.announce( - "passing a constructor as a block", - "Provide a `constructor:` keyword argument instead", - tag: "dry-configurable", - uplevel: 2 - ) + if Dry::Configurable.warn_on_setting_constructor_block + Dry::Core::Deprecations.announce( + "passing a constructor as a block", + "Provide a `constructor:` keyword argument instead", + tag: "dry-configurable", + uplevel: 2 + ) + end + options = options.merge(constructor: block) block = nil end diff --git a/lib/dry/configurable/flags.rb b/lib/dry/configurable/flags.rb new file mode 100644 index 0000000..3829e18 --- /dev/null +++ b/lib/dry/configurable/flags.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "dry/core/class_attributes" + +module Dry + module Configurable + extend Core::ClassAttributes + + # Set to false to suppress deprecation warning when a setting default is provided as a + # positional argument + defines :warn_on_setting_positional_default + warn_on_setting_positional_default true + + # Set to false to suppress deprecation warning when a setting constructor is provided + # as a block + defines :warn_on_setting_constructor_block + warn_on_setting_constructor_block true + end +end diff --git a/spec/unit/dry/configurable/dsl_spec.rb b/spec/unit/dry/configurable/dsl_spec.rb index c2ddeb9..f467a8d 100644 --- a/spec/unit/dry/configurable/dsl_spec.rb +++ b/spec/unit/dry/configurable/dsl_spec.rb @@ -32,6 +32,21 @@ RSpec.describe Dry::Configurable::DSL do expect(logger.string).to match(/default value as positional argument to settings is deprecated/) end + it "compiles when giving a default as positional argument, and suppresses the warning when flagged off" do + Dry::Configurable.warn_on_setting_positional_default false + + logger = StringIO.new + Dry::Core::Deprecations.set_logger!(logger) + setting = dsl.setting :user, "root" + + expect(setting.name).to be(:user) + expect(setting.value).to eql("root") + logger.rewind + expect(logger.string).to be_empty + + Dry::Configurable.warn_on_setting_positional_default true + end + it "compiles but deprecates giving a defalt hash value as a positional argument (without any keyword args)" do # This test is necessary for behavior specific to Ruby 2.6 and 2.7 @@ -58,7 +73,7 @@ RSpec.describe Dry::Configurable::DSL do end end - it "compiles but deprecates giving a defalt hash value as a positional argument (with keyword args) " do + it "compiles but deprecates giving a defalt hash value as a positional argument (with keyword args)" do # This test is necessary for behavior specific to Ruby 2.6 and 2.7 logger = StringIO.new @@ -119,6 +134,22 @@ RSpec.describe Dry::Configurable::DSL do expect(logger.string).to match(/constructor as a block is deprecated/) end + it "supports but deprecates giving a constructor as a block, and suppresses the warning when flagged off" do + Dry::Configurable.warn_on_setting_constructor_block false + + logger = StringIO.new + Dry::Core::Deprecations.set_logger!(logger) + + setting = dsl.setting(:dsn, default: "sqlite") { |value| "jdbc:#{value}" } + + expect(setting.name).to be(:dsn) + expect(setting.value).to eql("jdbc:sqlite") + logger.rewind + expect(logger.string).to be_empty + + Dry::Configurable.warn_on_setting_constructor_block true + end + it "compiles a nested list of settings" do setting = dsl.setting(:db) do From c7f63e87c4187d28cac2695558501be0a2d5aae9 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Sun, 12 Sep 2021 21:47:39 +1000 Subject: [PATCH 24/82] Prepare changelog for 0.13.0 --- changelog.yml | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/changelog.yml b/changelog.yml index b703f53..7431ff3 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,17 +1,31 @@ --- -- version: unreleased +- version: 0.13.0 summary: - date: + date: '2021-09-12' fixed: - - 'Fix `ArgumentError` for classes including `Dry::Configurable` whose - `initializer` has required kwargs. (#113 by @timriley)' - - 'Remove implicit `to_hash` conversion from `Config`. (#114 by @timriley)' + - Fixed `ArgumentError` for classes including `Dry::Configurable` whose `initializer` has required kwargs. (#113 by @timriley) added: + - |- + Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) + + ```ruby + Dry::Configurable.warn_on_setting_constructor_block = false + Dry::Configurable.warn_on_setting_positional_default = false + ``` changed: - - 'Deprecate constructor as a block. Providing `constructor:` kwarg is now - the only accepted way. (#111 by @waiting-for-dev & @timriley)' - - 'Use `default:` kwarg instead of second positional argument for the - default value. (#112 by @waiting-for-dev & @timriley)' + - |- + Deprecated the setting constructor provided as a block. Provide it via the `constructor:` keyword argument instead. (#111 by @waiting-for-dev & @timriley) + + ```ruby + setting :path, constructor: -> path { Pathname(path) } + ``` + - |- + Deprecated the setting default provided as the second positional argument. Provide it via the `default:` keyword argument instead. (#112 and #121 by @waiting-for-dev & @timriley) + + ```ruby + setting :path, default: "some/default/path" + ``` + - '[BREAKING] Removed implicit `to_hash` conversion from `Config`. (#114 by @timriley)' - version: 0.12.1 summary: date: '2021-02-15' From e72680272b611045d2b7e789c31270ab7d37bdda Mon Sep 17 00:00:00 2001 From: dry-bot Date: Sun, 12 Sep 2021 11:48:05 +0000 Subject: [PATCH 25/82] [devtools] sync --- CHANGELOG.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 160f8d9..5fa08a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,36 @@ -## unreleased +## 0.13.0 2021-09-12 +### Added + +- Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) + + ```ruby + Dry::Configurable.warn_on_setting_constructor_block = false + Dry::Configurable.warn_on_setting_positional_default = false + ``` + ### Fixed -- Fix `ArgumentError` for classes including `Dry::Configurable` whose `initializer` has required kwargs. (#113 by @timriley) -- Remove implicit `to_hash` conversion from `Config`. (#114 by @timriley) +- Fixed `ArgumentError` for classes including `Dry::Configurable` whose `initializer` has required kwargs. (#113 by @timriley) ### Changed -- Deprecate constructor as a block. Providing `constructor:` kwarg is now the only accepted way. (#111 by @waiting-for-dev & @timriley) -- Use `default:` kwarg instead of second positional argument for the default value. (#112 by @waiting-for-dev & @timriley) +- Deprecated the setting constructor provided as a block. Provide it via the `constructor:` keyword argument instead. (#111 by @waiting-for-dev & @timriley) -[Compare v0.12.1...master](https://github.com/dry-rb/dry-configurable/compare/v0.12.1...master) + ```ruby + setting :path, constructor: -> path { Pathname(path) } + ``` +- Deprecated the setting default provided as the second positional argument. Provide it via the `default:` keyword argument instead. (#112 and #121 by @waiting-for-dev & @timriley) + + ```ruby + setting :path, default: "some/default/path" + ``` +- [BREAKING] Removed implicit `to_hash` conversion from `Config`. (#114 by @timriley) + +[Compare v0.12.1...v0.13.0](https://github.com/dry-rb/dry-configurable/compare/v0.12.1...v0.13.0) ## 0.12.1 2021-02-15 From 78e800dd30dfb6bb8730da7f0a9ff400419f49d9 Mon Sep 17 00:00:00 2001 From: Grant Hutchins Date: Mon, 13 Sep 2021 11:56:10 -0500 Subject: [PATCH 26/82] Fix typo in CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa08a8..d10bdb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ - Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) ```ruby - Dry::Configurable.warn_on_setting_constructor_block = false - Dry::Configurable.warn_on_setting_positional_default = false + Dry::Configurable.warn_on_setting_constructor_block false + Dry::Configurable.warn_on_setting_positional_default false ``` ### Fixed From 7adf0f2b236c25df4173d5e306575af3d2cc6611 Mon Sep 17 00:00:00 2001 From: dry-bot Date: Tue, 14 Sep 2021 07:51:46 +0000 Subject: [PATCH 27/82] [devtools] sync --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d10bdb2..5fa08a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ - Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) ```ruby - Dry::Configurable.warn_on_setting_constructor_block false - Dry::Configurable.warn_on_setting_positional_default false + Dry::Configurable.warn_on_setting_constructor_block = false + Dry::Configurable.warn_on_setting_positional_default = false ``` ### Fixed From b2f800d683664d12313de454bbd585200788fa48 Mon Sep 17 00:00:00 2001 From: File Sync Date: Tue, 21 Sep 2021 13:12:31 +0000 Subject: [PATCH 28/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 70e5787..cf73851 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -208,6 +208,12 @@ Style/CombinableLoops: Style/EmptyElse: Enabled: false +Style/DoubleNegation: + Enabled: false + +Style/MultilineBlockChain: + Enabled: false + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" From bf6321b454ef63d41d9d2077619981ae3bf719c4 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 25 Sep 2021 19:38:37 +0000 Subject: [PATCH 29/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4694cc4..eed6e37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: - "3.0" - "2.7" - "2.6" + - "jruby" include: - ruby: "3.0" coverage: "true" From b6e201dcfacd5029acd7c2c49dcddfc922c27612 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 25 Sep 2021 19:38:38 +0000 Subject: [PATCH 30/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edf7e41..01d82fd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This library officially supports the following Ruby versions: * MRI `>= 2.6.0` -* ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161)) +* jruby `>= 9.3` ## License From c110d9081e743ffa7cb49439cf1362aafbaf22df Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Tue, 12 Oct 2021 00:28:39 -0400 Subject: [PATCH 31/82] Clarify usage of flags to suppress warnings I believe that this fixes a typo in the changelog. --- changelog.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.yml b/changelog.yml index 7431ff3..04c0712 100644 --- a/changelog.yml +++ b/changelog.yml @@ -9,8 +9,8 @@ Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) ```ruby - Dry::Configurable.warn_on_setting_constructor_block = false - Dry::Configurable.warn_on_setting_positional_default = false + Dry::Configurable.warn_on_setting_constructor_block false + Dry::Configurable.warn_on_setting_positional_default false ``` changed: - |- From 69b6b27c1eb3d7a53867b45336440fdd56a4b3c0 Mon Sep 17 00:00:00 2001 From: dry-bot Date: Tue, 12 Oct 2021 07:32:58 +0000 Subject: [PATCH 32/82] [devtools] sync --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa08a8..d10bdb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ - Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley) ```ruby - Dry::Configurable.warn_on_setting_constructor_block = false - Dry::Configurable.warn_on_setting_positional_default = false + Dry::Configurable.warn_on_setting_constructor_block false + Dry::Configurable.warn_on_setting_positional_default false ``` ### Fixed From 82d6b2f938585b5fc7e8d4397b36f58da38a6ae3 Mon Sep 17 00:00:00 2001 From: Konnor Rogers Date: Tue, 16 Nov 2021 23:12:55 -0500 Subject: [PATCH 33/82] docs: add a note about configuration blocks --- docsite/source/index.html.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docsite/source/index.html.md b/docsite/source/index.html.md index 8735626..7e5eb2a 100644 --- a/docsite/source/index.html.md +++ b/docsite/source/index.html.md @@ -53,3 +53,23 @@ App.pool App.uploader.bucket # => 'dev' ``` + +`dry-configurable` also can be used to pass a configuration block like you may have seen in +other gems. + +Example: + +```ruby +class App + extend Dry::Configurable + setting :database +end + +App.config.database # => nil + +App.configure do |config| + config.database = "postgres" +end + +App.config.database # => "postgres" +``` From 21c8f85908bcc81c276932bab6a5119892cfba71 Mon Sep 17 00:00:00 2001 From: Konnor Rogers Date: Tue, 16 Nov 2021 23:14:07 -0500 Subject: [PATCH 34/82] Update index.html.md --- docsite/source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docsite/source/index.html.md b/docsite/source/index.html.md index 7e5eb2a..f3a34b4 100644 --- a/docsite/source/index.html.md +++ b/docsite/source/index.html.md @@ -54,7 +54,7 @@ App.uploader.bucket # => 'dev' ``` -`dry-configurable` also can be used to pass a configuration block like you may have seen in +`dry-configurable` can also be used to pass a configuration block like you may have seen in other gems. Example: From 94b3b58182cb4bf7dcf057cdf35c90b3d1022361 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 20 Dec 2021 05:35:27 +0000 Subject: [PATCH 35/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eed6e37..38900e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: COVERAGE_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}} steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install package dependencies run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS" - name: Set up Ruby @@ -62,7 +62,7 @@ jobs: GITHUB_LOGIN: dry-bot GITHUB_TOKEN: ${{secrets.GH_PAT}} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Install package dependencies run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS" - name: Set up Ruby From a224479c55777861e13a70fb9460b26d773a4ae8 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 20 Dec 2021 05:35:28 +0000 Subject: [PATCH 36/82] Update .github/workflows/sync_configs.yml from dry-rb/template-gem --- .github/workflows/sync_configs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync_configs.yml b/.github/workflows/sync_configs.yml index f4a85be..17463f5 100644 --- a/.github/workflows/sync_configs.yml +++ b/.github/workflows/sync_configs.yml @@ -17,7 +17,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GH_PAT }} steps: - name: Checkout ${{github.repository}} - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Checkout devtools uses: actions/checkout@v2 with: From dc18f3487acf40d55cf9422962cf1f0fbac5d9d8 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 22 Dec 2021 10:28:41 +0000 Subject: [PATCH 37/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38900e7..4fc91d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,7 @@ jobs: fail-fast: false matrix: ruby: + - "3.1.0-preview1" - "3.0" - "2.7" - "2.6" From 55df3ebf8feca5233db3c2f0626301405476323f Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Wed, 22 Dec 2021 14:22:55 +0300 Subject: [PATCH 38/82] [ci] Do not install hotch on jruby --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0ccff33..3fbfda8 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,6 @@ group :benchmarks do end group :tools do - gem 'hotch' + gem 'hotch', platform: :mri gem 'pry-byebug', platform: :mri end From 516250981e613eae3070c98c354211fe3692c2b5 Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Thu, 23 Dec 2021 13:57:05 +0300 Subject: [PATCH 39/82] [rubocop] autocorrect --- Gemfile | 10 +++++----- Rakefile | 4 ++-- bin/console | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 3fbfda8..8c6e685 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,16 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" -eval_gemfile 'Gemfile.devtools' +eval_gemfile "Gemfile.devtools" gemspec group :benchmarks do - gem 'benchmark-ips' + gem "benchmark-ips" end group :tools do - gem 'hotch', platform: :mri - gem 'pry-byebug', platform: :mri + gem "hotch", platform: :mri + gem "pry-byebug", platform: :mri end diff --git a/Rakefile b/Rakefile index ad52f83..be26d08 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rspec/core/rake_task' +require "rspec/core/rake_task" -desc 'Run all specs in spec directory' +desc "Run all specs in spec directory" RSpec::Core::RakeTask.new(:spec) task default: :spec diff --git a/bin/console b/bin/console index 936f50e..0afe571 100755 --- a/bin/console +++ b/bin/console @@ -1,13 +1,13 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'bundler/setup' -require 'dry/configurable' +require "bundler/setup" +require "dry/configurable" begin - require 'pry-byebug' + require "pry-byebug" Pry.start rescue LoadError - require 'irb' + require "irb" IRB.start end From 7e116237f3d161ad0930abd277f29e881a9052d4 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 27 Dec 2021 04:09:08 +0000 Subject: [PATCH 40/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fc91d9..1d840f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,13 +26,13 @@ jobs: fail-fast: false matrix: ruby: - - "3.1.0-preview1" + - "3.1" - "3.0" - "2.7" - "2.6" - "jruby" include: - - ruby: "3.0" + - ruby: "3.1" coverage: "true" env: COVERAGE: ${{matrix.coverage}} From 3c0b3c68b11888c56c6221b50b07adc877b212c4 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 5 Jan 2022 10:08:39 +0000 Subject: [PATCH 41/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01d82fd..2366838 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # dry-configurable [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat] [![Gem Version](https://badge.fury.io/rb/dry-configurable.svg)][gem] -[![CI Status](https://github.com/dry-rb/dry-configurable/workflows/CI/badge.svg)][actions] +[![CI Status](https://github.com/dry-rb/dry-configurable/workflows/ci/badge.svg)][actions] [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0276a97990e04eb0ac722b3e7f3620b5)][codacy] [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0276a97990e04eb0ac722b3e7f3620b5)][codacy] [![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=master)][inchpages] From bc754fec9f9a2f168013a28972ec2725854383f4 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 7 Jan 2022 10:12:30 +1100 Subject: [PATCH 42/82] Add missing default: argument in spec --- spec/integration/dry/configurable/setting_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/dry/configurable/setting_spec.rb b/spec/integration/dry/configurable/setting_spec.rb index cb98112..0b3dad5 100644 --- a/spec/integration/dry/configurable/setting_spec.rb +++ b/spec/integration/dry/configurable/setting_spec.rb @@ -328,8 +328,8 @@ RSpec.describe Dry::Configurable, ".setting" do klass.setting :env klass.setting :db do - setting :user, "root" - setting :pass, "secret" + setting :user, default: "root" + setting :pass, default: "secret" end end From 1e60d0c2ca4a02e62a12b256c012915f50b9efff Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 7 Jan 2022 11:26:31 +1100 Subject: [PATCH 43/82] Use proper default: argument in more places --- .../dry/configurable/setting_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/integration/dry/configurable/setting_spec.rb b/spec/integration/dry/configurable/setting_spec.rb index 0b3dad5..b9a010a 100644 --- a/spec/integration/dry/configurable/setting_spec.rb +++ b/spec/integration/dry/configurable/setting_spec.rb @@ -147,7 +147,7 @@ RSpec.describe Dry::Configurable, ".setting" do context "with a ruby keyword" do before do - klass.setting :if, true + klass.setting :if, default: true end it "works" do @@ -205,7 +205,7 @@ RSpec.describe Dry::Configurable, ".setting" do it "allows defining more settings" do klass.setting :db, default: "sqlite" - subclass.setting :username, "root" + subclass.setting :username, default: "root" subclass.setting :password subclass.config.password = "secret" @@ -308,13 +308,13 @@ RSpec.describe Dry::Configurable, ".setting" do end it "defines a constructor that sets the config" do - klass.setting :db, "sqlite" + klass.setting :db, default: "sqlite" expect(object.config.db).to eql("sqlite") end it "creates distinct setting values across instances" do - klass.setting(:path, "test", constructor: ->(m) { Pathname(m) }) + klass.setting(:path, default: "test", constructor: ->(m) { Pathname(m) }) new_object = klass.new @@ -365,7 +365,7 @@ RSpec.describe Dry::Configurable, ".setting" do end it "can be configured" do - klass.setting :db, "sqlite" + klass.setting :db, default: "sqlite" object.configure do |config| config.db = "mariadb" @@ -375,7 +375,7 @@ RSpec.describe Dry::Configurable, ".setting" do end it "can be finalized" do - klass.setting :db, "sqlite" + klass.setting :db, default: "sqlite" object.finalize! # becomes a no-op @@ -389,7 +389,7 @@ RSpec.describe Dry::Configurable, ".setting" do it "defines a reader shortcut for nested config" do klass.setting :dsn, reader: true do - setting :pool, 5 + setting :pool, default: 5 end expect(object.dsn.pool).to be(5) @@ -398,10 +398,10 @@ RSpec.describe Dry::Configurable, ".setting" do context "Test Interface" do describe "reset_config" do it "resets configuration to default values" do - klass.setting :dsn, nil + klass.setting :dsn, default: nil klass.setting :pool do - setting :size, nil + setting :size, default: nil end object.enable_test_interface From deec13e8acc3580ffc0c956b061bed8d39989112 Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:16 +0000 Subject: [PATCH 44/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d840f9..b67ae72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,6 @@ jobs: - "3.1" - "3.0" - "2.7" - - "2.6" - "jruby" include: - ruby: "3.1" @@ -69,7 +68,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6 + ruby-version: 2.7 - name: Install dependencies run: gem install ossy --no-document - name: Trigger release workflow From 35f26021951224506acf16f63f1319e7582ed12c Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:17 +0000 Subject: [PATCH 45/82] Update .github/workflows/docsite.yml from dry-rb/template-gem --- .github/workflows/docsite.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docsite.yml b/.github/workflows/docsite.yml index 3b4ade8..d15795c 100644 --- a/.github/workflows/docsite.yml +++ b/.github/workflows/docsite.yml @@ -1,4 +1,4 @@ -# this file is managed by dry-rb/devtools project +# This file is synced from dry-rb/template-gem repo name: docsite @@ -24,7 +24,7 @@ jobs: - name: Set up Ruby uses: actions/setup-ruby@v1 with: - ruby-version: "2.6.x" + ruby-version: "2.7.x" - name: Set up git user run: | git config --local user.email "dry-bot@dry-rb.org" From 0f6d291b8835ce33b7f879afc8b0bdc2e04deece Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:18 +0000 Subject: [PATCH 46/82] Update .github/workflows/sync_configs.yml from dry-rb/template-gem --- .github/workflows/sync_configs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync_configs.yml b/.github/workflows/sync_configs.yml index 17463f5..a75b611 100644 --- a/.github/workflows/sync_configs.yml +++ b/.github/workflows/sync_configs.yml @@ -30,7 +30,7 @@ jobs: - name: Set up Ruby uses: actions/setup-ruby@v1 with: - ruby-version: "2.6" + ruby-version: "2.7" - name: Install dependencies run: gem install ossy --no-document - name: Update changelog.yml from commit From 003f2c1995f0e779c7189d9c477810bb6b287de1 Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:19 +0000 Subject: [PATCH 47/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index cf73851..1f45df0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ # This is a config synced from dry-rb/template-gem repo AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 2.7 NewCops: enable Exclude: - benchmarks/*.rb From 50d1deeaafdbee5f59c7fa7f44e36400118a4445 Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:20 +0000 Subject: [PATCH 48/82] Update dry-configurable.gemspec from dry-rb/template-gem --- dry-configurable.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dry-configurable.gemspec b/dry-configurable.gemspec index bd3b621..5c66a1a 100644 --- a/dry-configurable.gemspec +++ b/dry-configurable.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |spec| spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-configurable" spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-configurable/issues" - spec.required_ruby_version = ">= 2.6.0" + spec.required_ruby_version = ">= 2.7.0" # to update dependencies edit project.yml spec.add_runtime_dependency "concurrent-ruby", "~> 1.0" From 473774840df761947bfef812028b663bd5f752ad Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:36:21 +0000 Subject: [PATCH 49/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2366838..a23200d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This library officially supports the following Ruby versions: -* MRI `>= 2.6.0` +* MRI `>= 2.7.0` * jruby `>= 9.3` ## License From 7e6477434e7116f887d106047f56d07abddb35b0 Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:46:19 +0000 Subject: [PATCH 50/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b67ae72..9f3fb81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,6 @@ jobs: - "3.1" - "3.0" - "2.7" - - "jruby" include: - ruby: "3.1" coverage: "true" From 82caa2371bdb29b86c9c170a82e352e277ab001f Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 13 Jan 2022 16:46:20 +0000 Subject: [PATCH 51/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a23200d..6725b51 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This library officially supports the following Ruby versions: * MRI `>= 2.7.0` -* jruby `>= 9.3` +* jruby `>= 9.3` (postponed until 2.7 is supported) ## License From 7d6db4d9fd6da267caf6a5604b799c2f53bf7101 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 14 Jan 2022 11:01:07 +1100 Subject: [PATCH 52/82] Allow settings to be defined and accessible after class-level `config` access (#130) --- lib/dry/configurable/class_methods.rb | 12 ++++-- lib/dry/configurable/config.rb | 2 +- lib/dry/configurable/instance_methods.rb | 4 ++ lib/dry/configurable/setting.rb | 10 ++++- .../dry/configurable/setting_spec.rb | 37 ++++++++++++++++++- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/lib/dry/configurable/class_methods.rb b/lib/dry/configurable/class_methods.rb index 6a7e028..ff7edf4 100644 --- a/lib/dry/configurable/class_methods.rb +++ b/lib/dry/configurable/class_methods.rb @@ -13,12 +13,11 @@ module Dry include Methods # @api private - def inherited(klass) + def inherited(subclass) super - parent_settings = (respond_to?(:config) ? config._settings : _settings) - - klass.instance_variable_set("@_settings", parent_settings) + subclass.instance_variable_set("@_settings", _settings.dup) + subclass.instance_variable_set("@_config", config.dup) if respond_to?(:config) end # Add a setting to the configuration @@ -71,6 +70,11 @@ module Dry # # @api public def config + # The _settings provided to the Config remain shared between the class and the + # Config. This allows settings defined _after_ accessing the config to become + # available in subsequent accesses to the config. The config is duped when + # subclassing to ensure it remains distinct between subclasses and parent classes + # (see `.inherited` above). @config ||= Config.new(_settings) end diff --git a/lib/dry/configurable/config.rb b/lib/dry/configurable/config.rb index ba320d4..f97e549 100644 --- a/lib/dry/configurable/config.rb +++ b/lib/dry/configurable/config.rb @@ -23,7 +23,7 @@ module Dry # @api private def initialize(settings) - @_settings = settings.dup + @_settings = settings @_resolved = Concurrent::Map.new end diff --git a/lib/dry/configurable/instance_methods.rb b/lib/dry/configurable/instance_methods.rb index c86085a..25474a7 100644 --- a/lib/dry/configurable/instance_methods.rb +++ b/lib/dry/configurable/instance_methods.rb @@ -12,7 +12,11 @@ module Dry module Initializer # @api private def initialize(*) + # Dup settings at time of initializing to ensure setting values are specific to + # this instance. This does mean that any settings defined on the class _after_ + # initialization will not be available on the instance. @config = Config.new(self.class._settings.dup) + super end ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true) diff --git a/lib/dry/configurable/setting.rb b/lib/dry/configurable/setting.rb index dd36f02..f7bde10 100644 --- a/lib/dry/configurable/setting.rb +++ b/lib/dry/configurable/setting.rb @@ -62,9 +62,17 @@ module Dry def initialize(name, input: Undefined, default: Undefined, **options) @name = name @writer_name = :"#{name}=" + @options = options + + # Setting collections (see `Settings`) are shared between the configurable class + # and its `config` object, so for cloneable individual settings, we duplicate + # their _values_ as early as possible to ensure no impact from unintended mutation @input = input @default = default - @options = options + if cloneable? + @input = input.dup + @default = default.dup + end evaluate if input_defined? end diff --git a/spec/integration/dry/configurable/setting_spec.rb b/spec/integration/dry/configurable/setting_spec.rb index b9a010a..48098e8 100644 --- a/spec/integration/dry/configurable/setting_spec.rb +++ b/spec/integration/dry/configurable/setting_spec.rb @@ -185,6 +185,15 @@ RSpec.describe Dry::Configurable, ".setting" do include_context "configurable behavior" + specify "settings defined after accessing config are still available in the config" do + klass.setting :before, default: "defined before" + klass.config + klass.setting :after, default: "defined after" + + expect(klass.config.before).to eq "defined before" + expect(klass.config.after).to eq "defined after" + end + context "with a subclass" do let(:subclass) do Class.new(klass) @@ -225,7 +234,7 @@ RSpec.describe Dry::Configurable, ".setting" do expect(subclass.settings).to eql(Set[:db]) end - it "configured parent copies config to the child" do + specify "configuring the parent before subclassing copies the config to the child" do klass.setting :db object.config.db = "mariadb" @@ -233,6 +242,16 @@ RSpec.describe Dry::Configurable, ".setting" do expect(subclass.config.db).to eql("mariadb") end + specify "configuring the parent after subclassing does not copy the config to the child" do + klass.setting :db + + subclass = Class.new(klass) + + object.config.db = "mariadb" + + expect(subclass.config.db).to be nil + end + it "not configured parent does not set child config" do klass.setting :db @@ -323,6 +342,22 @@ RSpec.describe Dry::Configurable, ".setting" do expect(object.config.path).not_to be(new_object.config.path) end + it "makes only settings defined before instantiation available" do + klass.setting :before, default: "defined before" + + object_1 = klass.new + + klass.setting :after, default: "defined after" + + object_2 = klass.new + + expect(object_1.config.before).to eq "defined before" + expect(object_1.config).not_to respond_to(:after) + + expect(object_2.config.before).to eq "defined before" + expect(object_2.config.after).to eq "defined after" + end + shared_examples "copying" do before do klass.setting :env From 954b70d7957b7311a3de22bf9f0a52e41de3eaa1 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 14 Jan 2022 11:10:45 +1100 Subject: [PATCH 53/82] Prepare changelog for 0.14.0 --- changelog.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/changelog.yml b/changelog.yml index 04c0712..eac2c75 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,4 +1,14 @@ --- +- version: 0.14.0 + summary: + date: '2022-01-14' + changed: + - |- + Settings defined after an access to `config` will still be made available on that `config`. (#130 by @timriley) + - |- + Cloneable settings are cloned immediately upon assignment. (#130 by @timriley) + - |- + Changes to config values in parent classes after subclasses have already been created will not be propogated to those subclasses. Subclasses created _after_ config values have been changed in the parent _will_ receive those config values. (#130 by @timriley) - version: 0.13.0 summary: date: '2021-09-12' From 3349adbd9927833c0d0ff18488503bc00177524e Mon Sep 17 00:00:00 2001 From: dry-bot Date: Fri, 14 Jan 2022 00:11:10 +0000 Subject: [PATCH 54/82] [devtools] sync --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d10bdb2..e674039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ +## 0.14.0 2022-01-14 + + +### Changed + +- Settings defined after an access to `config` will still be made available on that `config`. (#130 by @timriley) +- Cloneable settings are cloned immediately upon assignment. (#130 by @timriley) +- Changes to config values in parent classes after subclasses have already been created will not be propogated to those subclasses. Subclasses created _after_ config values have been changed in the parent _will_ receive those config values. (#130 by @timriley) + +[Compare v0.13.0...v0.14.0](https://github.com/dry-rb/dry-configurable/compare/v0.13.0...v0.14.0) + ## 0.13.0 2021-09-12 From 72233add2e83ad1d46ff57d9cc664fe09cf2d6b8 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 14 Jan 2022 11:12:49 +1100 Subject: [PATCH 55/82] Bump dry-configurable to 0.14.0 --- lib/dry/configurable/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dry/configurable/version.rb b/lib/dry/configurable/version.rb index c009756..73aeecb 100755 --- a/lib/dry/configurable/version.rb +++ b/lib/dry/configurable/version.rb @@ -3,6 +3,6 @@ module Dry module Configurable # @api public - VERSION = "0.13.0" + VERSION = "0.14.0" end end From 5e51131f2607c9faf8476648156179cdd20b3f27 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 17 Jan 2022 04:01:27 +0000 Subject: [PATCH 56/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 1f45df0..e9a19a7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -137,6 +137,9 @@ Style/EachWithObject: Style/FormatString: Enabled: false +Style/FormatStringToken: + Enabled: false + Style/GuardClause: Enabled: false From 1bf7bdd2e026b7ab0e29dfea8c8a76e5110b7b47 Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 17 Jan 2022 09:29:33 +0000 Subject: [PATCH 57/82] Update Gemfile.devtools from dry-rb/template-gem --- Gemfile.devtools | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile.devtools b/Gemfile.devtools index 673e2c0..4bac325 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -13,6 +13,5 @@ group :test do end group :tools do - # this is the same version that we use on codacy - gem "rubocop", "1.16.0" + gem "rubocop", "~> 1.24.0" end From 3b8b08a9b3ca5bc8866083ac446cdebbf42ed7f6 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 19 Jan 2022 13:40:19 +0000 Subject: [PATCH 58/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index e9a19a7..75620f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -257,3 +257,6 @@ Naming/VariableNumber: Naming/BinaryOperatorParameterName: Enabled: false + +Style/NumberedParametersLimit: + Max: 2 From 09877ccf449897042bc2b29dd39ca496e5b373ff Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 20 Jan 2022 03:55:23 +0000 Subject: [PATCH 59/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 75620f6..fe6f090 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -217,6 +217,9 @@ Style/DoubleNegation: Style/MultilineBlockChain: Enabled: false +Style/NumberedParametersLimit: + Max: 2 + Lint/UnusedBlockArgument: Exclude: - "spec/**/*.rb" @@ -257,6 +260,3 @@ Naming/VariableNumber: Naming/BinaryOperatorParameterName: Enabled: false - -Style/NumberedParametersLimit: - Max: 2 From d2d9b663c6d6e006f88f6dfc9eb61c6fb3b01a3e Mon Sep 17 00:00:00 2001 From: File Sync Date: Thu, 20 Jan 2022 03:55:24 +0000 Subject: [PATCH 60/82] Update Gemfile.devtools from dry-rb/template-gem --- Gemfile.devtools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.devtools b/Gemfile.devtools index 4bac325..b041991 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -13,5 +13,5 @@ group :test do end group :tools do - gem "rubocop", "~> 1.24.0" + gem "rubocop", "~> 1.24.1" end From 8663f8dff11aea86947a695ac203d37dfef864a1 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 26 Jan 2022 19:11:12 +0000 Subject: [PATCH 61/82] Update Gemfile.devtools from dry-rb/template-gem --- Gemfile.devtools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.devtools b/Gemfile.devtools index b041991..ba95e76 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -13,5 +13,5 @@ group :test do end group :tools do - gem "rubocop", "~> 1.24.1" + gem "rubocop", "~> 1.25.0" end From 16b2f8cbc3274e672793669b4348823011cdc58b Mon Sep 17 00:00:00 2001 From: File Sync Date: Fri, 18 Mar 2022 10:32:34 +0000 Subject: [PATCH 62/82] Update .github/FUNDING.yml from dry-rb/template-gem --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 89dec09..31b7f31 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -github: [jodosha, solnic, timriley] +github: hanami From 94f67fa2025e6906a688f9ff8fc6fc8fa972ba56 Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 23 Mar 2022 21:15:26 +0000 Subject: [PATCH 63/82] Update Gemfile.devtools from dry-rb/template-gem --- Gemfile.devtools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.devtools b/Gemfile.devtools index ba95e76..2b7f09c 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -13,5 +13,5 @@ group :test do end group :tools do - gem "rubocop", "~> 1.25.0" + gem "rubocop", "~> 1.26.1" end From 34b4ff4ffdff14502a6e81fb7807bc178cbca156 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 2 Apr 2022 13:03:24 +0000 Subject: [PATCH 64/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f3fb81..356b176 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ on: - "project.yml" pull_request: branches: - - master + - main create: jobs: @@ -48,7 +48,7 @@ jobs: - name: Run all tests run: bundle exec rake - name: Run codacy-coverage-reporter - uses: codacy/codacy-coverage-reporter-action@master + uses: codacy/codacy-coverage-reporter-action@main if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != '' with: project-token: ${{secrets.CODACY_PROJECT_TOKEN}} From eea04e44e59ae37dba17379ab6b7c4bf1987821a Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 2 Apr 2022 13:03:25 +0000 Subject: [PATCH 65/82] Update .github/workflows/docsite.yml from dry-rb/template-gem --- .github/workflows/docsite.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docsite.yml b/.github/workflows/docsite.yml index d15795c..4928420 100644 --- a/.github/workflows/docsite.yml +++ b/.github/workflows/docsite.yml @@ -8,7 +8,7 @@ on: - docsite/** - .github/workflows/docsite.yml branches: - - master + - main - release-** tags: @@ -51,7 +51,7 @@ jobs: git push --all "https://dry-bot:${{secrets.GH_PAT}}@github.com/$GITHUB_REPOSITORY.git" - git checkout master + git checkout main else echo "no need to update branches" fi From 1922279cc413db13d9a06941dc7af8cb5325abd8 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 2 Apr 2022 13:03:26 +0000 Subject: [PATCH 66/82] Update .github/workflows/sync_configs.yml from dry-rb/template-gem --- .github/workflows/sync_configs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync_configs.yml b/.github/workflows/sync_configs.yml index a75b611..1fe1407 100644 --- a/.github/workflows/sync_configs.yml +++ b/.github/workflows/sync_configs.yml @@ -6,7 +6,7 @@ on: repository_dispatch: push: branches: - - "master" + - "main" jobs: main: @@ -43,5 +43,5 @@ jobs: git commit -m "[devtools] sync" || echo "nothing to commit" - name: Push changes run: | - git pull --rebase origin master - git push https://dry-bot:${{secrets.GH_PAT}}@github.com/${{github.repository}}.git HEAD:master + git pull --rebase origin main + git push https://dry-bot:${{secrets.GH_PAT}}@github.com/${{github.repository}}.git HEAD:main From c1d2ce101e6541280a19f9f911ae881f99d18838 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 2 Apr 2022 13:03:27 +0000 Subject: [PATCH 67/82] Update dry-configurable.gemspec from dry-rb/template-gem --- dry-configurable.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dry-configurable.gemspec b/dry-configurable.gemspec index 5c66a1a..0b6caa3 100644 --- a/dry-configurable.gemspec +++ b/dry-configurable.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.metadata["allowed_push_host"] = "https://rubygems.org" - spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md" + spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md" spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-configurable" spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-configurable/issues" From 833528ad2443d229cd1ee65cab40249d0d57940c Mon Sep 17 00:00:00 2001 From: File Sync Date: Sat, 2 Apr 2022 13:03:28 +0000 Subject: [PATCH 68/82] Update README.md from dry-rb/template-gem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6725b51..4ad1e76 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![CI Status](https://github.com/dry-rb/dry-configurable/workflows/ci/badge.svg)][actions] [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0276a97990e04eb0ac722b3e7f3620b5)][codacy] [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0276a97990e04eb0ac722b3e7f3620b5)][codacy] -[![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=master)][inchpages] +[![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=main)][inchpages] ## Links From 374bafbfc6acc20288e7727625a2a83aef09c075 Mon Sep 17 00:00:00 2001 From: File Sync Date: Sun, 3 Apr 2022 09:52:53 +0000 Subject: [PATCH 69/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 356b176..f180017 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: - name: Run all tests run: bundle exec rake - name: Run codacy-coverage-reporter - uses: codacy/codacy-coverage-reporter-action@main + uses: codacy/codacy-coverage-reporter-action@master if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != '' with: project-token: ${{secrets.CODACY_PROJECT_TOKEN}} From d1591474a9ec5f851742506b450a2e98c6ff7a7c Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 11 Apr 2022 08:38:39 +0000 Subject: [PATCH 70/82] Update .rubocop.yml from dry-rb/template-gem --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index fe6f090..7d84ef1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ AllCops: TargetRubyVersion: 2.7 - NewCops: enable + NewCops: disable Exclude: - benchmarks/*.rb - spec/support/coverage.rb From 53de7253c203254334ef9a59231ea79a5c8a22ee Mon Sep 17 00:00:00 2001 From: File Sync Date: Mon, 11 Apr 2022 08:38:40 +0000 Subject: [PATCH 71/82] Update Gemfile.devtools from dry-rb/template-gem --- Gemfile.devtools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.devtools b/Gemfile.devtools index 2b7f09c..b235923 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -13,5 +13,5 @@ group :test do end group :tools do - gem "rubocop", "~> 1.26.1" + gem "rubocop", "~> 1.27.0" end From 5a3c2c76c4be3f89b487dad882f7497eddafab17 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Mon, 18 Apr 2022 08:41:28 +0200 Subject: [PATCH 72/82] Delete CHANGELOG.old.md --- CHANGELOG.old.md | 94 ------------------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 CHANGELOG.old.md diff --git a/CHANGELOG.old.md b/CHANGELOG.old.md deleted file mode 100644 index ddc7a54..0000000 --- a/CHANGELOG.old.md +++ /dev/null @@ -1,94 +0,0 @@ -## 0.9.0 - 2019-11-06 - -## Fixed - -- Support for reserved names in settings. Some Kernel methods (`public_send` and `class` specifically) are not available if you use access settings via method call. Same for methods of the `Config` class. You can still access them with `[]` and `[]=`. Ruby keywords are fully supported. Invalid names containing special symbols (including `!` and `?`) are rejected. Note that these changes don't affect the `reader` option, if you define a setting named `:class` and pass `reader: true` ... well ... (flash-gordon) -- Settings can be redefined in subclasses without a warning about overriding exsting methods (flash-gordon) -- Fix warnings about using keyword arguments in 2.7 (koic) - -[Compare v0.8.3...v0.9.0](https://github.com/dry-rb/dry-configurable/compare/v0.8.3...v0.9.0) - -## 0.8.3 - 2019-05-29 - -## Fixed - -- `Configurable#dup` and `Configurable#clone` make a copy of instance-level config so that it doesn't get mutated/shared across instances (flash-gordon) - -[Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-configurable/compare/v0.8.2...v0.8.3) - -## 0.8.2 - 2019-02-25 - -## Fixed - -- Test interface support for modules ([Neznauy](https://github.com/Neznauy)) - -[Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-configurable/compare/v0.8.1...v0.8.2) - -## 0.8.1 - 2019-02-06 - -## Fixed - -- `.configure` doesn't require a block, this makes the behavior consistent with the previous versions ([flash-gordon](https://github.com/flash-gordon)) - -[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-configurable/compare/v0.8.0...v0.8.1) - -## 0.8.0 - 2019-02-05 - -## Fixed - -- A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon)) - -## Added - -- Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon)) - - ```ruby - class App - include Dry::Configurable - - setting :database - end - - production = App.new - production.config.database = ENV['DATABASE_URL'] - production.finalize! - - development = App.new - development.config.database = 'jdbc:sqlite:memory' - development.finalize! - ``` - -- Config values can be set from a hash with `.update`. Nested settings are supported ([flash-gordon](https://github.com/flash-gordon)) - - ```ruby - class App - extend Dry::Configurable - - setting :db do - setting :host - setting :port - end - - config.update(YAML.load(File.read("config.yml"))) - end - ``` - -## Changed - -- [BREAKING] Minimal supported Ruby version is set to 2.3 ([flash-gordon](https://github.com/flash-gordon)) - -[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-configurable/compare/v0.7.0...v0.8.0) - -## 0.7.0 - 2017-04-25 - -## Added - -- Introduce `Configurable.finalize!` which freezes config and its dependencies ([qcam](https://github.com/qcam)) - -## Fixed - -- Allow for boolean false as default setting value ([yuszuv](https://github.com/yuszuv)) -- Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox)) -- Disallow modification on frozen config ([qcam](https://github.com/qcam)) - -[Compare v0.6.2...v0.7.0](https://github.com/dry-rb/dry-configurable/compare/v0.6.2...v0.7.0) From 265fb9c1eed24b4bc86c87259be88dba780c167a Mon Sep 17 00:00:00 2001 From: Taylor Scott Date: Mon, 18 Apr 2022 04:04:27 -0700 Subject: [PATCH 73/82] Update docs (#132) The current documentation is slightly out of date. Update the docs to better reflect the preferred methodology within the codebase. Co-authored-by: Nikita Shilnikov --- docsite/source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docsite/source/index.html.md b/docsite/source/index.html.md index 8735626..d19e5ee 100644 --- a/docsite/source/index.html.md +++ b/docsite/source/index.html.md @@ -31,7 +31,7 @@ class App # Construct values setting :path, default: 'test', constructor: proc { |value| Pathname(value) } # Passing the reader option as true will create attr_reader method for the class - setting :pool, 5, reader: true + setting :pool, default: 5, reader: true # Passing the reader attributes works with nested configuration setting :uploader, reader: true do setting :bucket, default: 'dev' From 44f6e4561b6548b09e387108522e2a98530502e2 Mon Sep 17 00:00:00 2001 From: ojab Date: Thu, 21 Apr 2022 08:14:48 +0300 Subject: [PATCH 74/82] Make `Config#finalize!` finalize itself recurively and allow freezing values (#105) Fixes #104 --- lib/dry/configurable/config.rb | 4 +-- lib/dry/configurable/instance_methods.rb | 4 +-- lib/dry/configurable/methods.rb | 6 ++--- lib/dry/configurable/setting.rb | 21 ++++++++++----- lib/dry/configurable/settings.rb | 6 +++++ .../dry/configurable/setting_spec.rb | 26 +++++++++++++++++-- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/lib/dry/configurable/config.rb b/lib/dry/configurable/config.rb index f97e549..6bdad08 100644 --- a/lib/dry/configurable/config.rb +++ b/lib/dry/configurable/config.rb @@ -81,8 +81,8 @@ module Dry alias_method :to_h, :values # @api private - def finalize! - _settings.freeze + def finalize!(freeze_values: false) + _settings.finalize!(freeze_values: freeze_values) freeze end diff --git a/lib/dry/configurable/instance_methods.rb b/lib/dry/configurable/instance_methods.rb index 25474a7..4870cb4 100644 --- a/lib/dry/configurable/instance_methods.rb +++ b/lib/dry/configurable/instance_methods.rb @@ -38,9 +38,7 @@ module Dry # Finalize the config and freeze the object # # @api public - def finalize! - return self if frozen? - + def finalize!(freeze_values: false) super freeze end diff --git a/lib/dry/configurable/methods.rb b/lib/dry/configurable/methods.rb index c6bcff8..ec07bdf 100644 --- a/lib/dry/configurable/methods.rb +++ b/lib/dry/configurable/methods.rb @@ -21,10 +21,8 @@ module Dry # @return [Dry::Configurable::Config] # # @api public - def finalize! - return self if config.frozen? - - config.finalize! + def finalize!(freeze_values: false) + config.finalize!(freeze_values: freeze_values) self end end diff --git a/lib/dry/configurable/setting.rb b/lib/dry/configurable/setting.rb index f7bde10..5c1ada7 100644 --- a/lib/dry/configurable/setting.rb +++ b/lib/dry/configurable/setting.rb @@ -84,8 +84,12 @@ module Dry # @api private def value - @value ||= evaluate + return @value if evaluated? + + @value = constructor[Undefined.coalesce(input, default, nil)] end + alias_method :evaluate, :value + private :evaluate # @api private def evaluated? @@ -102,6 +106,16 @@ module Dry with(input: Undefined) end + # @api private + def finalize!(freeze_values: false) + if value.is_a?(Config) + value.finalize!(freeze_values: freeze_values) + elsif freeze_values + value.freeze + end + freeze + end + # @api private def with(new_opts) self.class.new(name, input: input, default: default, **options, **new_opts) @@ -149,11 +163,6 @@ module Dry @value = source.value.dup if source.evaluated? end end - - # @api private - def evaluate - @value = constructor[Undefined.coalesce(input, default, nil)] - end end end end diff --git a/lib/dry/configurable/settings.rb b/lib/dry/configurable/settings.rb index 3784e17..bab8334 100644 --- a/lib/dry/configurable/settings.rb +++ b/lib/dry/configurable/settings.rb @@ -54,6 +54,12 @@ module Dry self.class.new(map(&:pristine)) end + # @api private + def finalize!(freeze_values: false) + each { |element| element.finalize!(freeze_values: freeze_values) } + freeze + end + private # @api private diff --git a/spec/integration/dry/configurable/setting_spec.rb b/spec/integration/dry/configurable/setting_spec.rb index 48098e8..82ca90c 100644 --- a/spec/integration/dry/configurable/setting_spec.rb +++ b/spec/integration/dry/configurable/setting_spec.rb @@ -363,7 +363,7 @@ RSpec.describe Dry::Configurable, ".setting" do klass.setting :env klass.setting :db do - setting :user, default: "root" + setting :user, default: "root".dup setting :pass, default: "secret" end end @@ -410,13 +410,35 @@ RSpec.describe Dry::Configurable, ".setting" do end it "can be finalized" do - klass.setting :db, default: "sqlite" + klass.setting :kafka, default: "kafka://127.0.0.1:9092" object.finalize! # becomes a no-op object.finalize! expect(object).to be_frozen + expect(object.config.db).to be_frozen + expect(object.config.db.user).not_to be_frozen + + object.config.db.user << "foo" + expect(object.config.db.user).to eq("rootfoo") + + # does not allow configure block anymore + expect { object.configure {} }.to raise_error(Dry::Configurable::FrozenConfig) + end + + it "can be finalized with freezing values" do + klass.setting :kafka, "kafka://127.0.0.1:9092" + + object.finalize!(freeze_values: true) + # becomes a no-op + object.finalize!(freeze_values: true) + + expect(object).to be_frozen + expect(object.config.db).to be_frozen + expect(object.config.db.user).to be_frozen + + expect { object.config.db.user << "foo" }.to raise_error(FrozenError) # does not allow configure block anymore expect { object.configure {} }.to raise_error(Dry::Configurable::FrozenConfig) From 5a5efd7d2e84fd6dc2515afa50cbf45a23ec24af Mon Sep 17 00:00:00 2001 From: ojab Date: Thu, 21 Apr 2022 08:44:59 +0300 Subject: [PATCH 75/82] Allow Hash as a possible config value (#131) --- lib/dry/configurable/config.rb | 7 +++++-- .../dry/configurable/config_spec.rb | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/dry/configurable/config.rb b/lib/dry/configurable/config.rb index 6bdad08..a18cac3 100644 --- a/lib/dry/configurable/config.rb +++ b/lib/dry/configurable/config.rb @@ -57,8 +57,11 @@ module Dry # @api public def update(values) values.each do |key, value| - case value - when Hash + if self[key].is_a?(self.class) + unless value.is_a?(Hash) + raise ArgumentError, "#{value.inspect} is not a valid setting value" + end + self[key].update(value) else self[key] = value diff --git a/spec/integration/dry/configurable/config_spec.rb b/spec/integration/dry/configurable/config_spec.rb index ded560e..a375063 100644 --- a/spec/integration/dry/configurable/config_spec.rb +++ b/spec/integration/dry/configurable/config_spec.rb @@ -35,6 +35,27 @@ RSpec.describe Dry::Configurable::Config do expect(klass.config.db.user).to eql("jane") expect(klass.config.db.pass).to eql("supersecret") end + + it "runs constructors" do + klass.setting :db do + setting :user, default: "root", constructor: ->(v) { v.upcase } + setting :sslcert, constructor: ->(v) { v&.values_at(:pem, :pass)&.join } + end + + klass.config.update(db: {user: "jane", sslcert: {pem: "cert", pass: "qwerty"}}) + + expect(klass.config.db.user).to eql("JANE") + expect(klass.config.db.sslcert).to eql("certqwerty") + end + + it "raises ArgumentError when setting value is not a Hash" do + klass.setting :db do + setting :user + end + + expect { klass.config.update(db: "string") } + .to raise_error(ArgumentError, '"string" is not a valid setting value') + end end describe "#to_h" do From 45dd19eac4ce5cb58fb2b19bcbc62e3eba4122be Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Thu, 21 Apr 2022 16:47:19 +1000 Subject: [PATCH 76/82] Accept any to_hash-convertible in Config#update (#133) --- lib/dry/configurable/config.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/dry/configurable/config.rb b/lib/dry/configurable/config.rb index a18cac3..a8bdc31 100644 --- a/lib/dry/configurable/config.rb +++ b/lib/dry/configurable/config.rb @@ -50,7 +50,7 @@ module Dry # Update config with new values # - # @param values [Hash] A hash with new values + # @param values [Hash, #to_hash] A hash with new values # # @return [Config] # @@ -58,11 +58,11 @@ module Dry def update(values) values.each do |key, value| if self[key].is_a?(self.class) - unless value.is_a?(Hash) + unless value.respond_to?(:to_hash) raise ArgumentError, "#{value.inspect} is not a valid setting value" end - self[key].update(value) + self[key].update(value.to_hash) else self[key] = value end From 0bae0ea79fee6048c453870b1242eeee1ef5f4e2 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Thu, 21 Apr 2022 17:08:56 +1000 Subject: [PATCH 77/82] Prepare changelog for 0.15.0 --- changelog.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/changelog.yml b/changelog.yml index eac2c75..6d1422f 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,4 +1,35 @@ --- +- version: 0.15.0 + summary: + date: '2022-04-21' + changed: + - |- + 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) + + ```ruby + class MyConfigurable + include Dry::Configurable + + setting :db, default: "postgre" + end + + my_obj = MyConfigurable.new + my_obj.finalize!(freeze_values: true) + my_obj.config.db << "sql" # Will raise FrozenError + ``` + - |- + `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash`, and will set hashes as values for non-nested settings (#131 by @ojab, #133 by @timriley) + + ```ruby + class MyConfigurable + extend Dry::Configurable + + setting :sslcert, constructor: ->(v) { v&.values_at(:pem, :pass)&.join } + end + + MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"}) + MyConfigurable.config.sslcert # => "certqwerty" + ``` - version: 0.14.0 summary: date: '2022-01-14' From 68501c2b19a17f319504be706b0a79e6ad3d1204 Mon Sep 17 00:00:00 2001 From: dry-bot Date: Thu, 21 Apr 2022 07:09:18 +0000 Subject: [PATCH 78/82] [devtools] sync --- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e674039..8c73bc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,38 @@ +## 0.15.0 2022-04-21 + + +### Changed + +- 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) + + ```ruby + class MyConfigurable + include Dry::Configurable + + setting :db, default: "postgre" + end + + my_obj = MyConfigurable.new + my_obj.finalize!(freeze_values: true) + my_obj.config.db << "sql" # Will raise FrozenError + ``` +- `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash`, and will set hashes as values for non-nested settings (#131 by @ojab, #133 by @timriley) + + ```ruby + class MyConfigurable + extend Dry::Configurable + + setting :sslcert, constructor: ->(v) { v&.values_at(:pem, :pass)&.join } + end + + MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"}) + MyConfigurable.config.sslcert # => "certqwerty" + ``` + +[Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-configurable/compare/v0.14.0...v0.15.0) + ## 0.14.0 2022-01-14 From dc5d2c4f372d8cc4b95564ad607e24238a308ca3 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Thu, 21 Apr 2022 17:23:53 +1000 Subject: [PATCH 79/82] Update changelog for 0.15.0 --- changelog.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog.yml b/changelog.yml index 6d1422f..c9395cf 100644 --- a/changelog.yml +++ b/changelog.yml @@ -18,7 +18,7 @@ my_obj.config.db << "sql" # Will raise FrozenError ``` - |- - `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash`, and will set hashes as values for non-nested settings (#131 by @ojab, #133 by @timriley) + `Dry::Configurable::Config#update` will set hashes as values for non-nested settings (#131 by @ojab) ```ruby class MyConfigurable @@ -30,6 +30,8 @@ MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"}) MyConfigurable.config.sslcert # => "certqwerty" ``` + - |- + `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash` (#133 by @timriley) - version: 0.14.0 summary: date: '2022-01-14' From 3b8d1641619f120ff5195ea53e02c00dd1f104cf Mon Sep 17 00:00:00 2001 From: dry-bot Date: Thu, 21 Apr 2022 07:24:17 +0000 Subject: [PATCH 80/82] [devtools] sync --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c73bc5..3ddcbd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ my_obj.finalize!(freeze_values: true) my_obj.config.db << "sql" # Will raise FrozenError ``` -- `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash`, and will set hashes as values for non-nested settings (#131 by @ojab, #133 by @timriley) +- `Dry::Configurable::Config#update` will set hashes as values for non-nested settings (#131 by @ojab) ```ruby class MyConfigurable @@ -30,6 +30,7 @@ MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"}) MyConfigurable.config.sslcert # => "certqwerty" ``` +- `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash` (#133 by @timriley) [Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-configurable/compare/v0.14.0...v0.15.0) From 4ad54e46d8353241525a591d6eaf36b3659c1d57 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Thu, 21 Apr 2022 17:28:50 +1000 Subject: [PATCH 81/82] Bump dry-configurable to 0.15.0 --- lib/dry/configurable/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dry/configurable/version.rb b/lib/dry/configurable/version.rb index 73aeecb..616ac55 100755 --- a/lib/dry/configurable/version.rb +++ b/lib/dry/configurable/version.rb @@ -3,6 +3,6 @@ module Dry module Configurable # @api public - VERSION = "0.14.0" + VERSION = "0.15.0" end end From 54acb64a20f187ecae80654abc1009f06f1daaad Mon Sep 17 00:00:00 2001 From: File Sync Date: Wed, 22 Jun 2022 07:43:25 +0000 Subject: [PATCH 82/82] Update .github/workflows/ci.yml from dry-rb/template-gem --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f180017..fc27ad6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,12 +47,6 @@ jobs: bundler-cache: true - name: Run all tests run: bundle exec rake - - name: Run codacy-coverage-reporter - uses: codacy/codacy-coverage-reporter-action@master - if: env.COVERAGE == 'true' && env.COVERAGE_TOKEN != '' - with: - project-token: ${{secrets.CODACY_PROJECT_TOKEN}} - coverage-reports: coverage/coverage.xml release: runs-on: ubuntu-latest if: contains(github.ref, 'tags') && github.event_name == 'create'