Skip to content

Commit

Permalink
Prefix mixed in ivars to ensure no clashes (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley authored Nov 16, 2022
1 parent c7f0287 commit 48e3430
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/dry/configurable/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def inherited(subclass)
subclass.instance_variable_set(:@__config_extension__, __config_extension__)

new_settings = settings.dup
subclass.instance_variable_set(:@_settings, new_settings)
subclass.instance_variable_set(:@__settings__, new_settings)

# Only classes **extending** Dry::Configurable have class-level config. When
# Dry::Configurable is **included**, the class-level config method is undefined because it
# resides at the instance-level instead (see `Configurable.included`).
if respond_to?(:config)
subclass.instance_variable_set(:@config, config.dup_for_settings(new_settings))
subclass.instance_variable_set(:@__config__, config.dup_for_settings(new_settings))
end
end

Expand Down Expand Up @@ -56,7 +56,7 @@ def setting(*args, **options, &block)
#
# @api public
def settings
@_settings ||= Settings.new
@__settings__ ||= Settings.new
end

# Return configuration
Expand All @@ -65,7 +65,7 @@ def settings
#
# @api public
def config
@config ||= __config_build__
@__config__ ||= __config_build__
end

# @api private
Expand Down
8 changes: 5 additions & 3 deletions lib/dry/configurable/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Configurable
module Initializer
# @api private
def initialize(*)
@config = self.class.__config_build__(self.class.settings)
@__config__ = self.class.__config_build__(self.class.settings)

super
end
Expand All @@ -30,7 +30,9 @@ module InstanceMethods
# @return [Config]
#
# @api public
attr_reader :config
def config
@__config__
end

# Finalize the config and freeze the object
#
Expand All @@ -45,7 +47,7 @@ def finalize!(freeze_values: false)
# @api public
def initialize_copy(source)
super
@config = source.config.dup
@__config__ = source.config.dup
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/configurable/test_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module TestInterface
#
# @api public
def reset_config
@config = config.pristine
@__config__ = config.pristine
end
end

Expand Down

0 comments on commit 48e3430

Please sign in to comment.