Module: ActiveScaffold::Configurable

Included in:
ActiveScaffold::Config::Base, ActiveScaffold::Config::Base, DataStructures::ActionColumns, DataStructures::Column, DataStructures::Columns, DataStructures::Set
Defined in:
lib/active_scaffold/configurable.rb

Overview

Exposes a configure method that accepts a block and runs all contents of the block in two contexts, as opposed to the normal one. First, everything gets evaluated as part of the object including Configurable. Then, as a failover, missing methods and variables are evaluated in the original binding of the block.

Note that this only works with “barewords”. Constants, instance variables, and class variables are not currently supported in both contexts.

May add the given functionality at both the class and instance level. For the former, use extend, and for the latter, use include.

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(name, *args)

this method will surely need tweaking. for example, i'm not sure if it should call super before or after it tries to eval with the binding.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_scaffold/configurable.rb', line 17

def method_missing(name, *args)
  begin
    super
  rescue NoMethodError, NameError
    if @configuration_binding.nil?
      raise $!
    else
      @configuration_binding.send(name, *args)
    end
  end
end

Instance Method Details

- (Object) configure(&configuration_block)



8
9
10
11
12
13
14
# File 'lib/active_scaffold/configurable.rb', line 8

def configure(&configuration_block)
  return unless configuration_block
  @configuration_binding = eval("self", configuration_block.binding)
  ret = instance_exec self, &configuration_block
  @configuration_binding = nil
  return ret
end