Module: ROM::Configurable::ClassMethods
- Includes:
- Methods
- Defined in:
- lib/rom/support/configurable/class_methods.rb
Instance Method Summary collapse
- #__config_dsl__ ⇒ Object private
- #__config_reader__ ⇒ Object private
-
#_settings ⇒ Settings
Return declared settings.
-
#config ⇒ Config
Return configuration.
- #configure {|config| ... } ⇒ Object included from Methods
-
#finalize! ⇒ ROM::Configurable::Config
included
from Methods
Finalize and freeze configuration.
- #inherited(subclass) ⇒ Object private
-
#setting(*args, **options) { ... } ⇒ ROM::Configurable::Config
Add a setting to the configuration.
-
#settings ⇒ Set<Symbol>
Return declared settings.
Instance Method Details
#__config_dsl__ ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 |
# File 'lib/rom/support/configurable/class_methods.rb', line 81 def __config_dsl__ @__config_dsl__ ||= DSL.new end |
#__config_reader__ ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rom/support/configurable/class_methods.rb', line 86 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 ⇒ Settings
Return declared settings
62 63 64 |
# File 'lib/rom/support/configurable/class_methods.rb', line 62 def _settings @_settings ||= Settings.new end |
#config ⇒ Config
Return configuration
71 72 73 74 75 76 77 78 |
# File 'lib/rom/support/configurable/class_methods.rb', line 71 def config # The _settings provided to the Config remain shared between the class and the # Config. This allows settings defined _after_ accessing the config to become # available in subsequent accesses to the config. The config is duped when # subclassing to ensure it remains distinct between subclasses and parent classes # (see `.inherited` above). @config ||= Config.new(_settings) end |
#configure {|config| ... } ⇒ Object Originally defined in module Methods
#finalize! ⇒ ROM::Configurable::Config Originally defined in module Methods
Finalize and freeze configuration
#inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 |
# File 'lib/rom/support/configurable/class_methods.rb', line 15 def inherited(subclass) super subclass.instance_variable_set("@_settings", _settings.dup) subclass.instance_variable_set("@_config", config.dup) if respond_to?(:config) end |
#setting(*args, **options) { ... } ⇒ ROM::Configurable::Config
Add a setting to the configuration
38 39 40 41 42 43 44 45 46 |
# File 'lib/rom/support/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 ⇒ Set<Symbol>
Return declared settings
53 54 55 |
# File 'lib/rom/support/configurable/class_methods.rb', line 53 def settings @settings ||= Set[*_settings.map(&:name)] end |