Sha256: b5514d8ab5f40d4aa13e380757e04bf3512e05aa245b0722acf5677b4bc08b47

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

module ComponentTester

  class << self

    ##
    #
    #
    # @return [Module] an anonymous module which includes the ComponentTester module.
    #
    def new(component_name, component_directory)
      component_directory = File.expand_path component_directory
      main_file = component_directory + "/#{component_name}/#{component_name}.rb"

      component_manager = Adhearsion::Components::ComponentManager.new(component_directory)
      component_module  = Adhearsion::Components::ComponentManager::ComponentDefinitionContainer.load_file main_file

      Module.new do

        extend ComponentTester

        (class << self; self; end).send(:define_method, :component_manager)   { component_manager   }
        (class << self; self; end).send(:define_method, :component_name)      { component_name      }
        (class << self; self; end).send(:define_method, :component_module)    { component_module    }
        (class << self; self; end).send(:define_method, :component_directory) { component_directory }


        define_method(:component_manager)   { component_manager   }
        define_method(:component_name)      { component_name      }
        define_method(:component_module)    { component_module    }
        define_method(:component_directory) { component_directory }

        def self.const_missing(name)
          component_module.const_get name
        end

      end
    end
  end

  def helper_method(name)
    Object.new.extend(component_module).method(name)
  end

  def config
    component_manager.configuration_for_component_named component_name
  end

  def initialize!
    metadata = component_module.metaclass.send(:instance_variable_get, :@metadata)
    if metadata && metadata[:initialization_block].kind_of?(Proc)
      metadata[:initialization_block].call
    end
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
adhearsion-1.0.1 lib/adhearsion/component_manager/component_tester.rb
adhearsion-1.0.0 lib/adhearsion/component_manager/component_tester.rb
rene-adhearsion-0.8.6 lib/adhearsion/component_manager/component_tester.rb
adhearsion-0.8.6 lib/adhearsion/component_manager/component_tester.rb
adhearsion-0.8.5 lib/adhearsion/component_manager/component_tester.rb
adhearsion-0.8.4 lib/adhearsion/component_manager/component_tester.rb