Class: Vagrant::Plugin
- Inherits:
-
Object
- Object
- Vagrant::Plugin
- Defined in:
- lib/vagrant/plugin.rb
Overview
Represents a single plugin and also manages loading plugins from
RubyGems. If a plugin has a vagrant_init.rb
file somewhere on its
load path, then this class will find it and load it. For logging purposes
(for debugging), the list of loaded plugins is stored in the Plugin.plugins
array.
Constant Summary collapse
- @@plugins =
The array of loaded plugins.
[]
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
The path to the
vagrant_init.rb
file which was loaded for this plugin. -
#gemspec ⇒ Object
readonly
The gemspec of this plugin.
Class Method Summary collapse
-
.load! ⇒ Object
Loads all the plugins for Vagrant.
-
.plugins ⇒ Array
Returns the array of plugins which are currently loaded by Vagrant.
Instance Method Summary collapse
-
#initialize(spec, file) ⇒ Plugin
constructor
Initializes a new plugin, given a Gemspec and the path to the gem's
vagrant_init.rb
file.
Constructor Details
#initialize(spec, file) ⇒ Plugin
Initializes a new plugin, given a Gemspec and the path to the
gem's vagrant_init.rb
file. This should never be called manually.
Instead load! creates all the instances.
72 73 74 75 76 77 |
# File 'lib/vagrant/plugin.rb', line 72 def initialize(spec, file) @gemspec = spec @file = file load file end |
Instance Attribute Details
#file ⇒ Object (readonly)
The path to the vagrant_init.rb
file which was loaded for this plugin.
17 18 19 |
# File 'lib/vagrant/plugin.rb', line 17 def file @file end |
#gemspec ⇒ Object (readonly)
The gemspec of this plugin. This is an actual gemspec object.
14 15 16 |
# File 'lib/vagrant/plugin.rb', line 14 def gemspec @gemspec end |
Class Method Details
.load! ⇒ Object
Loads all the plugins for Vagrant. Plugins are currently gems which have a "vagrant_init.rb" somewhere on their load path. This file is loaded to kick off the load sequence for that plugin.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vagrant/plugin.rb', line 23 def self.load! # Our version is used for checking dependencies our_version = Gem::Version.create(Vagrant::VERSION) # RubyGems 1.8.0 deprecated `source_index`. Gem::Specification is the # new replacement. For now, we support both, but special-case 1.8.x # so that we avoid deprecation messages. index = Gem::VERSION >= "1.8.0" ? Gem::Specification : Gem.source_index # Stupid hack since Rails 2.3.x overrides Gem.source_index with their # own incomplete replacement which causes issues. index = [index.installed_source_index, index.vendor_source_index] if defined?(Rails::VendorGemSourceIndex) && index.is_a?(Rails::VendorGemSourceIndex) # Look for a vagrant_init.rb in all the gems, but only the # latest version of the gems. [index].flatten.each do |source| # In 1.6.0, added the option of including prerelease gems, which is # useful for developers. specs = Gem::VERSION >= "1.6.0" ? source.latest_specs(true) : source.latest_specs specs.each do |spec| # If this gem depends on Vagrant, verify this is a valid release of # Vagrant for this gem to load into. vagrant_dep = spec.dependencies.find { |d| d.name == "vagrant" } next if vagrant_dep && !vagrant_dep.requirement.satisfied_by?(our_version) # Find a vagrant_init.rb to verify if this is a plugin file = nil if Gem::VERSION >= "1.8.0" file = spec.matches_for_glob("**/vagrant_init.rb").first else file = Gem.searcher.matching_files(spec, "vagrant_init.rb").first end next if !file @@plugins << new(spec, file) end end end |
.plugins ⇒ Array
Returns the array of plugins which are currently loaded by Vagrant.
67 |
# File 'lib/vagrant/plugin.rb', line 67 def self.plugins; @@plugins; end |