module Dry::Configurable::ClassMethods
Public Class Methods
define(name)
click to toggle source
# File lib/dry/configurable/class_methods.rb, line 94 def self.define(name) define_method(name) do config[name] end end
Public Instance Methods
__config_build__(settings = self.settings)
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 72 def __config_build__(settings = self.settings) __config_extension__.config_class.new(settings) end
__config_dsl__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 82 def __config_dsl__ @__config_dsl__ ||= DSL.new( config_class: __config_extension__.config_class, default_undefined: __config_extension__.default_undefined ) end
__config_extension__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 77 def __config_extension__ @__config_extension__ end
__config_reader__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 90 def __config_reader__ @__config_reader__ ||= begin reader = Module.new do def self.define(name) define_method(name) do config[name] end end end if included_modules.include?(InstanceMethods) include(reader) end extend(reader) reader end end
config()
click to toggle source
Return configuration
@return [Config]
@api public
# File lib/dry/configurable/class_methods.rb, line 67 def config @__config__ ||= __config_build__ end
inherited(subclass)
click to toggle source
@api private
Calls superclass method
# File lib/dry/configurable/class_methods.rb, line 11 def inherited(subclass) super subclass.instance_variable_set(:@__config_extension__, __config_extension__) new_settings = settings.dup 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)) end end
setting(*args, **options, &block)
click to toggle source
Add a setting to the configuration
@param [Mixed] name
The accessor key for the configuration value
@param [Mixed] default
Default value for the setting
@param [#call] constructor
Transformation given value will go through
@param [Boolean] reader
Whether a reader accessor must be created
@yield
A block can be given to add nested settings.
@return [Dry::Configurable::Config]
@api public
# File lib/dry/configurable/class_methods.rb, line 43 def setting(*args, **options, &block) setting = __config_dsl__.setting(*args, **options, &block) settings << setting __config_reader__.define(setting.name) if setting.reader? self end
settings()
click to toggle source
Returns the defined settings for the class.
@return [Settings]
@api public
# File lib/dry/configurable/class_methods.rb, line 58 def settings @__settings__ ||= Settings.new end