Class: Juicer::Command::Install

Inherits:
CmdParse::Command
  • Object
show all
Includes:
Util
Defined in:
lib/juicer/command/install.rb

Overview

Installs a third party library so Juicer can use it.

Instance Method Summary collapse

Methods included from Util

#files, #relative

Constructor Details

#initialize(io = nil) ⇒ Install

Initializes command



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/juicer/command/install.rb', line 14

def initialize(io = nil)
  super('install', false, true)
  @io = io || Logger.new(STDOUT)
  @version = nil
  @path = Juicer.home
  self.short_desc = "Install a third party library"
  self.description = <<-EOF
Installs a third party used by Juicer. Downloads necessary binaries and licenses
into Juicer installation directory, usually ~/.juicer
  EOF

  self.options = CmdParse::OptionParserWrapper.new do |opt|
    opt.on('-v', '--version [VERSION]', 'Specify version of library to install') { |version| @version = version }
  end
end

Instance Method Details

#execute(*args) ⇒ Object

Execute command



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/juicer/command/install.rb', line 32

def execute(*args)
  args.flatten!

  if args.length == 0
    raise ArgumentError.new('Please provide a library to install')
  end

  args.each do |lib|
    installer = Juicer::Install.get(lib).new(@path)
    path = File.join(installer.install_dir, installer.path)
    version = version(installer)

    if installer.installed?(version)
      @io.info "#{installer.name} #{version} is already installed in #{path}"
      break
    end

    installer.install(version)
    @io.info "Successfully installed #{lib.camel_case} #{version} in #{path}" if installer.installed?(version)
  end
end

#version(installer) ⇒ Object

Returns which version to install



56
57
58
# File 'lib/juicer/command/install.rb', line 56

def version(installer)
  @version ||= installer.latest
end