module Dry::Configurable::ClassMethods
Public Class Methods
define(name)
click to toggle source
# File lib/dry/configurable/class_methods.rb, line 87 def self.define(name) define_method(name) do config[name] end end
Public Instance Methods
__config_dsl__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 78 def __config_dsl__ @__config_dsl__ ||= DSL.new end
__config_reader__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 83 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
_settings()
click to toggle source
Return declared settings
@return [Settings]
@api public
# File lib/dry/configurable/class_methods.rb, line 64 def _settings @_settings ||= Settings.new end
config()
click to toggle source
Return configuration
@return [Config]
@api public
# File lib/dry/configurable/class_methods.rb, line 73 def config @config ||= Config.new(_settings) end
inherited(klass)
click to toggle source
@api private
Calls superclass method
# File lib/dry/configurable/class_methods.rb, line 16 def inherited(klass) super parent_settings = (respond_to?(:config) ? config._settings : _settings) klass.instance_variable_set("@_settings", parent_settings) 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 40 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
Return declared settings
@return [Set<Symbol>]
@api public
# File lib/dry/configurable/class_methods.rb, line 55 def settings @settings ||= Set[*_settings.map(&:name)] end