Module: ConfigurationBlocks

Defined in:
lib/configuration-blocks/core.rb,
lib/configuration-blocks/version.rb

Overview

Author

Paweł Wilk ([email protected])

Copyright

© 2012 by Paweł Wilk

License

This program is licensed under the terms of GNU Lesser General Public License or Ruby License.

This file contains version information.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#configuration_block(base = self, &block) ⇒ Module, Object

Returns configuration module that delegates methods pointing to the given base object and optionally evaluates the given block in the context of this module or in the current context.

If a block is given then it is evaluated in the context of the configuration module. If a block with at least one argument is given then the context remains as it was but the first argument is the module.

Examples:

# using external access to configuration module:
x.configuration_block do |c|
  c.some_setting  :a
  c.other_setting :b
end

# using internal access to configuration module:
x.configuration_block do
  some_setting  :a
  other_setting :b
end

Parameters:

  • base (Object, Symbol) (defaults to: self)

    base object which delegators will point to (defaults to object on which this method has been called). If symbol is given, then it should contain the name of a method that will be called on current object.

Returns:

  • (Module, Object)

    configuration module if not block is given or a block takes no arguments. In case of one or more arguments in a block it also returns a module unless break statement is used; in such case the value passed to break is returned.



25
26
27
# File 'lib/configuration-blocks/core.rb', line 25

def configuration_block(base = self, &block)
  self.class.configuration_block(base, &block)
end