Class: Derelict::Plugin::Manager
- Inherits:
-
Object
- Object
- Derelict::Plugin::Manager
- Extended by:
- Memoist
- Includes:
- Utils::Logger
- Defined in:
- lib/derelict/plugin/manager.rb
Overview
A class that handles managing plugins for a Vagrant instance
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
-
#description ⇒ Object
Provides a description of this Connection.
-
#fetch(plugin_name) ⇒ Object
Retrieves a plugin with a particular name.
-
#initialize(instance) ⇒ Manager
constructor
Initializes a Manager for use with a particular instance.
-
#install(plugin_name, options = {}) ⇒ Object
Installs a plugin (optionally a particular version).
-
#installed?(plugin_name, version = nil) ⇒ Boolean
Determines whether a particular plugin is installed.
-
#list ⇒ Object
Retrieves the Set of currently installed plugins.
-
#uninstall(plugin_name, options = {}) ⇒ Object
Uninstalls a particular Vagrant plugin.
-
#update(plugin_name, options = {}) ⇒ Object
Updates a particular Vagrant plugin.
Methods included from Utils::Logger
Constructor Details
#initialize(instance) ⇒ Manager
Initializes a Manager for use with a particular instance
* instance: The Derelict::Instance which will have its
plugins managed by this Manager
17 18 19 20 |
# File 'lib/derelict/plugin/manager.rb', line 17 def initialize(instance) @instance = instance logger.debug "Successfully initialized #{description}" end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
11 12 13 |
# File 'lib/derelict/plugin/manager.rb', line 11 def instance @instance end |
Instance Method Details
#description ⇒ Object
Provides a description of this Connection
Mainly used for log messages.
102 103 104 |
# File 'lib/derelict/plugin/manager.rb', line 102 def description "Derelict::Plugin::Manager for #{instance.description}" end |
#fetch(plugin_name) ⇒ Object
Retrieves a plugin with a particular name
* plugin_name: Name of the plugin to look for (as a string)
93 94 95 96 97 |
# File 'lib/derelict/plugin/manager.rb', line 93 def fetch(plugin_name) list.find {|plugin| plugin.name == plugin_name}.tap do |plugin| raise Plugin::NotFound.new plugin_name if plugin.nil? end end |
#install(plugin_name, options = {}) ⇒ Object
Installs a plugin (optionally a particular version)
If no version is specified, the latest stable version is used by Vagrant.
* plugin_name: Name of the plugin to install (as a string)
* options: Hash of options, valid keys:
* version: Particular version to install (optional,
latest version will be installed if omitted)
* log: Whether to log the output (optional, defaults
to false)
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/derelict/plugin/manager.rb', line 50 def install(plugin_name, = {}) = {:log => false, :version => nil}.merge() logger.info "Installing plugin '#{plugin_name}' using #{description}" version = [:version] command = [:plugin, "install", plugin_name] command.concat ["--plugin-version", version] unless version.nil? log_block = [:log] ? shell_log_block : nil instance.execute!(*command, &log_block).tap do flush_cache # flush memoized method return values end end |
#installed?(plugin_name, version = nil) ⇒ Boolean
Determines whether a particular plugin is installed
* plugin_name: Name of the plugin to look for (as a string)
33 34 35 36 37 |
# File 'lib/derelict/plugin/manager.rb', line 33 def installed?(plugin_name, version = nil) fetch(plugin_name).version == version or version.nil? rescue Plugin::NotFound false end |
#list ⇒ Object
Retrieves the Set of currently installed plugins
23 24 25 26 27 |
# File 'lib/derelict/plugin/manager.rb', line 23 def list logger.info "Retrieving Vagrant plugin list for #{description}" output = instance.execute!(:plugin, "list").stdout Derelict::Parser::PluginList.new(output).plugins end |
#uninstall(plugin_name, options = {}) ⇒ Object
Uninstalls a particular Vagrant plugin
* plugin_name: Name of the plugin to uninstall (as a string)
67 68 69 70 71 72 73 74 75 |
# File 'lib/derelict/plugin/manager.rb', line 67 def uninstall(plugin_name, = {}) = {:log => false}.merge() logger.info "Uninstalling plugin '#{plugin_name}' using #{description}" log_block = [:log] ? shell_log_block : nil instance.execute!(:plugin, "uninstall", plugin_name, &log_block).tap do flush_cache # flush memoized method return values end end |
#update(plugin_name, options = {}) ⇒ Object
Updates a particular Vagrant plugin
* plugin_name: Name of the plugin to update (as a string)
80 81 82 83 84 85 86 87 88 |
# File 'lib/derelict/plugin/manager.rb', line 80 def update(plugin_name, = {}) = {:log => false}.merge() logger.info "Updating plugin '#{plugin_name}' using #{description}" log_block = [:log] ? shell_log_block : nil instance.execute!(:plugin, "update", plugin_name, &log_block).tap do flush_cache # flush memoized method return values end end |