Class: Juicer::Install::RhinoInstaller

Inherits:
Base
  • Object
show all
Defined in:
lib/juicer/install/rhino_installer.rb

Overview

Install and uninstall routines for the Mozilla Rhino jar.

Instance Attribute Summary collapse

Attributes inherited from Base

#install_dir

Instance Method Summary collapse

Methods inherited from Base

#bin_path, #dependencies, #dependency, #download, #installed?, #log, #name, #path

Constructor Details

#initialize(install_dir = Juicer.home) ⇒ RhinoInstaller

Returns a new instance of RhinoInstaller.



13
14
15
16
17
# File 'lib/juicer/install/rhino_installer.rb', line 13

def initialize(install_dir = Juicer.home)
  super(install_dir)
  @latest = "1_7R2-RC1"
  @website = "http://ftp.mozilla.org/pub/mozilla.org/js/"
end

Instance Attribute Details

#latestObject (readonly)

Returns the value of attribute latest.



11
12
13
# File 'lib/juicer/install/rhino_installer.rb', line 11

def latest
  @latest
end

Instance Method Details

#install(version = nil) ⇒ Object

Install Rhino. Downloads the jar file and stores it in the installation directory along with the License text.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/juicer/install/rhino_installer.rb', line 23

def install(version = nil)
  version = super((version || latest).gsub(/\./, "_"))
  base = "rhino#{version}"
  filename = download(File.join(@website, "#{base}.zip"))
  target = File.join(@install_dir, path)

  Zip::ZipFile.open(filename) do |file|
    FileUtils.mkdir_p(File.join(target, version))

    begin
      file.extract("#{base.sub(/-RC\d/, "")}/LICENSE.txt", File.join(target, version, "LICENSE.txt"))
    rescue Exception
      # Fail silently, some releases don't carry the license
    end

    file.extract("#{base.sub(/-RC\d/, "")}/js.jar", File.join(target, "bin", "#{base}.jar"))
  end
end

#uninstall(version = nil) ⇒ Object

Uninstalls Rhino



45
46
47
48
49
50
# File 'lib/juicer/install/rhino_installer.rb', line 45

def uninstall(version = nil)
  super((version || latest).gsub(/\./, "_")) do |dir, version|
    base = "rhino#{version}"
    File.delete(File.join(dir, "bin/", "#{base}.jar"))
  end
end