lib/power_stencil/plugins/base.rb in power_stencil-0.5.1 vs lib/power_stencil/plugins/base.rb in power_stencil-0.6.0

- old
+ new

@@ -1,5 +1,6 @@ +require 'power_stencil/plugins/paths' require 'power_stencil/plugins/type' require 'power_stencil/plugins/config' require 'power_stencil/plugins/command_line' require 'power_stencil/plugins/entity_definitions' require 'power_stencil/plugins/templates' @@ -17,37 +18,43 @@ extend PowerStencil::Plugins::Gem include Climatic::Proxy include PowerStencil::Plugins::Type + include PowerStencil::Plugins::Paths include PowerStencil::Plugins::Config include PowerStencil::Plugins::CommandLine include PowerStencil::Plugins::Require include PowerStencil::Plugins::Capabilities include PowerStencil::Plugins::EntityDefinitions include PowerStencil::Plugins::Templates include PowerStencil::Plugins::Build include PowerStencil::Plugins::Dsl - attr_reader :name, :version, :entry_point_path + attr_reader :name, :version, :entry_point_path, :gem_spec - def initialize(name, project, type = :local) + def initialize(name, project, type: :local, gem_req: nil) @name = name @project = project @version = PowerStencil::Utils::SemanticVersion.new '0.0.0-not-specified' raise PowerStencil::Error, "Invalid plugin type (#{type}) for plugin '#{name}'" unless PLUGIN_TYPES.include? type @type = type + case type + when :gem + logger.debug "Plugin '#{name}' is provided as a Gem." + @gem_spec = PowerStencil::Plugins::Base.find_locally_installed_gem_spec name, gem_req + raise PowerStencil::Error, "Cannot find plugin '#{name}'. Try 'power_stencil plugin --install'" if gem_spec.nil? + raise PowerStencil::Error, "Invalid plugin '#{name}' ! Missing metadata 'plugin_name' in spec !" if gem_spec.metadata['plugin_name'].nil? + @name = gem_spec.metadata['plugin_name'] + logger.debug "Plugin real name is '#{name}'." + when :local + logger.debug "Plugin '#{name}' is provided locally by the project." + end + logger.debug "Loading plugin '#{name}'..." setup_plugin logger.info "Plugin '#{name}' successfully available" logger.debug "Plugin '#{name}' has following capabilities: #{capabilities.inspect}" - end - - def path - case type - when :local - project.project_plugin_path(name) - end end def plugin_module Object.const_get plugin_definition[:plugin_module] end \ No newline at end of file