Module: ConfigurationBlocks::ClassMethods
- Defined in:
- lib/configuration-blocks/core.rb
Overview
This module contains methods that will extend the class.
Instance Method Summary collapse
-
#configuration_block(base = self, &block) ⇒ Object
Returns configuration block.
-
#configuration_block_delegate(*methods) ⇒ nil
(also: #configuration_method, #configuration_methods, #settings_method)
This DSL method is intended to be used in a class or module to indicate which methods should be delegated.
-
#configuration_module(base = self) ⇒ Module
Creates and returns anonymous module containing delegators that point to methods from a class this module is included in or the given
base
. -
#get_configuration_methods(local_only = false) ⇒ Array<Symbol>
Gets all method names known to configuration engine.
Instance Method Details
#configuration_block(base = self, &block) ⇒ Object
Returns configuration block.
70 71 72 73 |
# File 'lib/configuration-blocks/core.rb', line 70 def configuration_block(base = self, &block) @cb_conf_module ||= configuration_module(base) configuration_block_core(@cb_conf_module, &block) end |
#configuration_block_delegate(*methods) ⇒ nil Also known as: configuration_method, configuration_methods, settings_method
This DSL method is intended to be used in a class or module to indicate which methods should be delegated.
119 120 121 122 123 |
# File 'lib/configuration-blocks/core.rb', line 119 def configuration_block_delegate(*methods) methods.flatten.each { |m| cf_block_delegators.add(m.to_sym) } @cb_conf_module = nil if @cb_conf_module nil end |
#configuration_module(base = self) ⇒ Module
Creates and returns anonymous module containing delegators that point to methods from a class this module is included in or the given base
.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/configuration-blocks/core.rb', line 84 def configuration_module(base = self) Module.new.tap do |cm| delegators = get_configuration_methods base = send(base) if base.is_a?(Symbol) cm.extend Module.new { delegators.each do |method| module_eval do define_method(method) do |*args| base.send(method, *args) end end end } end end |
#get_configuration_methods(local_only = false) ⇒ Array<Symbol>
Gets all method names known to configuration engine.
106 107 108 109 110 111 112 |
# File 'lib/configuration-blocks/core.rb', line 106 def get_configuration_methods(local_only = false) all_delegators = singleton_class.send(:cf_block_delegators) + cf_block_delegators return all_delegators if local_only ancestors.each_with_object(all_delegators) do |ancestor, all| all.merge(ancestor.send(__method__, true)) if ancestor.respond_to?(__method__) end end |