Class: VagrantPlugins::ProxyConf::Plugin

Inherits:
Vagrant::Plugin::V2::Plugin
  • Object
show all
Defined in:
lib/vagrant-proxyconf/plugin.rb,
lib/vagrant-proxyconf/hook.rb,
lib/vagrant-proxyconf/config.rb,
lib/vagrant-proxyconf/plugin.rb,
lib/vagrant-proxyconf/capability.rb

Overview

Vagrant Plugin class that registers all proxy configs, hooks, etc.

Constant Summary collapse

VAGRANT_VERSION_REQUIREMENT =

Compatible Vagrant versions

'>= 1.2.0'
OPTIONAL_PLUGIN_DEPENDENCIES =

A list of plugins whose action classes we hook to if installed

%w[vagrant-aws vagrant-omnibus vagrant-vbguest]

Class Method Summary collapse

Class Method Details

.check_vagrant_version(*requirements) ⇒ Boolean

Returns true if the Vagrant version fulfills the requirements

Parameters:

  • requirements (String, Array<String>)

    the version requirement

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/vagrant-proxyconf/plugin.rb', line 20

def self.check_vagrant_version(*requirements)
  Gem::Requirement.new(*requirements).satisfied_by?(
    Gem::Version.new(Vagrant::VERSION))
end

.check_vagrant_version!Object

Verifies that the Vagrant version fulfills the requirements

is incompatible with the Vagrant version

Raises:

  • (VagrantPlugins::ProxyConf::VagrantVersionError)

    if this plugin



29
30
31
32
33
34
35
36
37
# File 'lib/vagrant-proxyconf/plugin.rb', line 29

def self.check_vagrant_version!
  if !check_vagrant_version(VAGRANT_VERSION_REQUIREMENT)
    msg = I18n.t(
      'vagrant_proxyconf.errors.vagrant_version',
      requirement: VAGRANT_VERSION_REQUIREMENT.inspect)
    $stderr.puts msg
    raise msg
  end
end

.load_optional_dependenciesObject

Loads the plugins to ensure their action hooks are registered before us. Uses alphabetical order to not change the default behaviour otherwise.



72
73
74
75
76
# File 'lib/vagrant-proxyconf/plugin.rb', line 72

def self.load_optional_dependencies
  OPTIONAL_PLUGIN_DEPENDENCIES.sort.each do |plugin|
    load_optional_dependency plugin
  end
end

.load_optional_dependency(plugin) ⇒ Object

Ensures a dependent plugin is loaded before us if it is installed. Ignores Errors while loading, as Vagrant itself anyway shows them to user when it tries to load the plugin.

Parameters:

  • plugin (String)

    the plugin name



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-proxyconf/plugin.rb', line 50

def self.load_optional_dependency(plugin)
  logger = ProxyConf.logger
  logger.info "Trying to load #{plugin}"

  if check_vagrant_version('< 1.5.0.dev')
    begin
      Vagrant.require_plugin plugin
    rescue Vagrant::Errors::PluginLoadError
      logger.info "Ignoring the load error of #{plugin}"
    end
  else
    begin
      require plugin
    rescue Exception => e
      logger.info "Failed to load #{plugin}: #{e.inspect}"
      logger.info "Ignoring the error"
    end
  end
end

.setup_i18nObject

Initializes the internationalization strings



40
41
42
43
# File 'lib/vagrant-proxyconf/plugin.rb', line 40

def self.setup_i18n
  I18n.load_path << File.expand_path('../../../locales/en.yml', __FILE__)
  I18n.reload!
end