Sha256: 444a682e654eb5f4eb896ede776b88214525df0391fab7e7fdf04608407fc2da

Contents?: true

Size: 1.41 KB

Versions: 43

Compression:

Stored size: 1.41 KB

Contents

require File.join(File.dirname(__FILE__), "resource")

module PoolParty    
  module PluginModel
    
    def plugin(name=:plugin, cloud=nil, &block)
      plugins.has_key?(name) ? plugins[name] : (plugins[name] = PluginModel.new(name, cloud, &block))
    end
    alias_method :register_plugin, :plugin
    
    def plugins
      $plugins ||= {}
    end
    
    class PluginModel      
      attr_accessor :name, :klass
      attr_reader :parent
      include MethodMissingSugar
      include Configurable
      include PrettyPrinter      
      
      def initialize(name,cld,&block)
        @name = name
        @parent = cld
        class_string_name = "#{name}"
        
        # Create the class to evaluate the plugin on the implemented call
        klass = class_string_name.class_constant(PoolParty::Plugin::Plugin)
        klass.extend PoolParty::Resources
        klass.send :include, PoolParty::Resources

        # Create the block inside the instantiated plugin
        klass.module_eval &block if block
        
        # Store the name of the class for pretty printing later
        klass.name = name
        # Add the plugin definition to the cloud as an instance method
        Cloud::Cloud.module_eval <<-EOE
          def #{name}(parent=self, &block)
            @#{class_string_name.downcase} ||= #{class_string_name.class_constant}.new(parent, &block)
          end
        EOE
      end
      
    end
    
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
auser-poolparty-0.2.15 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.16 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.2 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.20 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.21 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.22 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.23 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.24 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.25 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.26 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.3 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.35 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.36 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.37 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.38 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.39 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.4 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.40 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.41 lib/poolparty/pool/plugin_model.rb
auser-poolparty-0.2.42 lib/poolparty/pool/plugin_model.rb