module Adorn::Delegate

Public Class Methods

extensions(m=Module.new, context=self, &block) click to toggle source

Creates and anonymous module and passes the result of the given block back to the context, extending the named @object instance variable. Provide an interface to append to Adorn::Cache during request

@param [Module, Object, Proc] @return [Module]

# File lib/adorn/delegate.rb, line 16
def self.extensions(m=Module.new, context=self, &block)
  return unless block_given?
  m.instance_eval do
    extensions = block.call # destructure this to handle more options
    if extensions.has_key?(:with)
      mods =  extensions[:with]
      include *mods
    end
  end

  context.instance_eval do
    define_method(:initialize) do |*args|

      obj, context, options = args
      @object               = obj
      @context              = context
      @options              = options if options
      @object.extend(m)
    end
  end
end