Sha256: 52c76e7d0f5d4d189bd1e73d155604b03d964b12edff46d1a43ca48e3742a3fb

Contents?: true

Size: 1.25 KB

Versions: 35

Compression:

Stored size: 1.25 KB

Contents

module ActiveScaffold
  # 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+.
  module Configurable
    def configure(&configuration_block)
      return unless configuration_block
      @configuration_binding = configuration_block.binding.eval('self')
      ret = instance_exec(self, &configuration_block)
      @configuration_binding = nil
      ret
    end

    # 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.
    def method_missing(name, *args)
      super
    rescue NoMethodError, NameError
      if @configuration_binding.nil?
        raise
      else
        @configuration_binding.send(name, *args)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
active_scaffold-3.5.5 lib/active_scaffold/configurable.rb
active_scaffold-3.5.4 lib/active_scaffold/configurable.rb
active_scaffold-3.5.3 lib/active_scaffold/configurable.rb
active_scaffold-3.5.2 lib/active_scaffold/configurable.rb
active_scaffold-3.5.1 lib/active_scaffold/configurable.rb
active_scaffold-3.5.0 lib/active_scaffold/configurable.rb
active_scaffold-3.4.43 lib/active_scaffold/configurable.rb
active_scaffold-3.4.42 lib/active_scaffold/configurable.rb
active_scaffold-3.4.41.1 lib/active_scaffold/configurable.rb
active_scaffold-3.4.41 lib/active_scaffold/configurable.rb
active_scaffold-3.4.40 lib/active_scaffold/configurable.rb
active_scaffold-3.4.39 lib/active_scaffold/configurable.rb
active_scaffold-3.4.38 lib/active_scaffold/configurable.rb
active_scaffold-3.4.37 lib/active_scaffold/configurable.rb
active_scaffold-3.4.36 lib/active_scaffold/configurable.rb
active_scaffold-3.4.35 lib/active_scaffold/configurable.rb
active_scaffold-3.4.34 lib/active_scaffold/configurable.rb
active_scaffold-3.4.33 lib/active_scaffold/configurable.rb
active_scaffold-3.4.32 lib/active_scaffold/configurable.rb
active_scaffold-3.4.31 lib/active_scaffold/configurable.rb