Skip to content

Commit

Permalink
Merge pull request #161 from emptyflask/emptyflask/nested-undefined
Browse files Browse the repository at this point in the history
[changelog]

version: unreleased
fixed: "Allow nested settings to default to `Undefined` (fixes #158 via #161) (@emptyflask)"
  • Loading branch information
solnic committed Jul 16, 2023
2 parents d75b828 + a908bc8 commit dea93f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dry/configurable/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Configurable
#
# @api private
class DSL
VALID_NAME = /\A[a-z_]\w*\z/i.freeze
VALID_NAME = /\A[a-z_]\w*\z/i

attr_reader :compiler

Expand Down Expand Up @@ -38,7 +38,7 @@ def setting(name, **options, &block) # rubocop:disable Metrics/AbcSize, Metrics/
node = [:setting, [name.to_sym, options]]

if block
ast << [:nested, [node, DSL.new(&block).ast]]
ast << [:nested, [node, DSL.new(**@options, &block).ast]]
else
ast << node
end
Expand Down
4 changes: 4 additions & 0 deletions spec/integration/dry/configurable/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
setting :foo
setting :bar, constructor: -> v { v.upcase }
setting :baz, default: "baz", constructor: -> v { v.upcase }
setting :qux do
setting :quux
end
end

expect(klass.config.foo).to be(Dry::Configurable::Undefined)
expect(klass.config.bar).to be(Dry::Configurable::Undefined)
expect(klass.config.baz).to eq "BAZ"
expect(klass.config.qux.quux).to be(Dry::Configurable::Undefined)

klass.configure do |config|
config.foo = "foo"
Expand Down

0 comments on commit dea93f5

Please sign in to comment.