Class: VagrantPlugins::Vundler::PluginCommand::Bundle

Inherits:
CommandPlugin::Command::Base
  • Object
show all
Includes:
Logging
Defined in:
lib/vundler/plugin_command/bundle.rb

Overview

Instance Method Summary collapse

Methods included from Logging

#vundler_debug

Constructor Details

#initializeBundle

Returns a new instance of Bundle.



13
14
15
16
17
18
19
20
21
# File 'lib/vundler/plugin_command/bundle.rb', line 13

def initialize(*)
  super

  if @env.local_data_path
    @local_gems_path = @env.local_data_path.join('gems')
  else
    vundler_debug 'Local data path is not set'
  end
end

Instance Method Details

#executeObject



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
# File 'lib/vundler/plugin_command/bundle.rb', line 23

def execute
  plugins_json = @env.cwd.join('plugins.json')

  if plugins_json.file?
    data = JSON.parse(plugins_json.read)
    vundler_debug "plugins.json data: #{data.inspect}"

    if data.any?
      @env.ui.info('Installing plugins...')

      data.each do |plugin|
        if plugin.is_a?(String)
          install plugin
        else
          install *plugin.first
        end
      end
      exit_code = 0
    else
      @env.ui.info('No plugins specified on plugins.json')
    end
  else
    @env.ui.error "No plugins.json found!"
    exit_code = 1
  end

  exit_code
end

#gem_helper(path) ⇒ Object



52
53
54
# File 'lib/vundler/plugin_command/bundle.rb', line 52

def gem_helper(path)
  CommandPlugin::GemHelper.new(path)
end

#install(plugin_name, version = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vundler/plugin_command/bundle.rb', line 67

def install(plugin_name, version = nil)
  plugin_name_label = plugin_name
  plugin_name_label += " (#{version})" if version

  versions = installed_gems.fetch(plugin_name, {}).keys
  vundler_debug "Installed versions for #{plugin_name}: #{versions}"

  if (versions.include? version) || (version.nil? && versions.any?)
    @env.ui.info("  -> #{plugin_name_label} already installed")
    return
  end

  gem_helper(@local_gems_path).with_environment do
    installer = Gem::DependencyInstaller.new(:document => [])

    begin
      @env.ui.info("  -> #{plugin_name_label} ")
      installer.install(plugin_name, version)
    rescue Gem::GemNotFoundException
      raise Vagrant::Errors::PluginInstallNotFound,
        :name => plugin_name
    end
  end
end

#installed_gemsObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/vundler/plugin_command/bundle.rb', line 56

def installed_gems
  @installed ||= {}.tap do |installed|
    # Combine project specific gems and global plugins
    gem_helper("#{@local_gems_path}#{::File::PATH_SEPARATOR}#{@env.gems_path}").with_environment do
      Gem::Specification.find_all.each do |spec|
        (installed[spec.name] ||= {})[spec.version.to_s] = spec
      end
    end
  end
end