Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dunderscore mixed in ivar names to ensure no clashes with user-set vars #159

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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