module Dry::Configurable::ClassMethods
Public Class Methods
define(name)
click to toggle source
# File lib/dry/configurable/class_methods.rb, line 85 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 76 def __config_dsl__ @dsl ||= DSL.new end
__config_reader__()
click to toggle source
@api private
# File lib/dry/configurable/class_methods.rb, line 81 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 62 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 71 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, &block)
click to toggle source
Add a setting to the configuration
@param [Mixed] key
The accessor key for the configuration value
@param [Mixed] default
The default config value
@yield
If a block is given, it will be evaluated in the context of a new configuration class, and bound as the default value
@return [Dry::Configurable::Config]
@api public
# File lib/dry/configurable/class_methods.rb, line 38 def setting(*args, &block) setting = __config_dsl__.setting(*args, &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 53 def settings @settings ||= Set[*_settings.map(&:name)] end