Class: Rip::Installer

Inherits:
Object
  • Object
show all
Includes:
Memoize
Defined in:
lib/rip/installer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Memoize

included, #memoize, #method_added

Constructor Details

#initializeInstaller

Returns a new instance of Installer.



6
7
8
9
# File 'lib/rip/installer.rb', line 6

def initialize
  @installed = {}
  @uninstalled = {}
end

Instance Attribute Details

#installedObject (readonly)

Returns the value of attribute installed.



5
6
7
# File 'lib/rip/installer.rb', line 5

def installed
  @installed
end

Instance Method Details

#build_extensions(package) ⇒ Object



65
66
67
# File 'lib/rip/installer.rb', line 65

def build_extensions(package)
  Rip::Commands.build({:quiet => true}, package)
end

#cleanup(package) ⇒ Object



86
87
88
# File 'lib/rip/installer.rb', line 86

def cleanup(package)
  FileUtils.rm_rf package.cache_path unless package.cached?
end

#copy_files(package) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rip/installer.rb', line 69

def copy_files(package)
  package_lib = File.join(package.cache_path, 'lib')
  package_bin = File.join(package.cache_path, 'bin')

  dest = Rip::Env.active_dir
  dest_lib = File.join(dest, 'lib')
  dest_bin = File.join(dest, 'bin')

  if File.exists? package_lib
    FileUtils.cp_r package_lib + '/.', dest_lib
  end

  if File.exists? package_bin
    FileUtils.cp_r package_bin + '/.', dest_bin, :preserve => true
  end
end

#install(package, parent = nil) ⇒ Object



16
17
18
19
20
21
22
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
# File 'lib/rip/installer.rb', line 16

def install(package, parent = nil)
  if !package.exists?
    error = package.to_s
    error += " requested by #{parent} but" if parent
    error += " not found at #{package.source}"
    ui.abort error
  end

  Dir.chdir File.join(Rip.dir, 'rip-packages') do
    begin
      installed = @installed[package.name] || package.installed?

      manager.add_package(package, parent) unless package.meta_package?

      return if installed
      @installed[package.name] = package

      if !package.meta_package? && !package.version
        ui.abort "can't install #{package} - it has no version"
      end

      package.fetch
      package.unpack
      install_dependencies(package)
      build_extensions(package)
      copy_files(package)
      cleanup(package)
      ui.puts "Successfully installed #{package}" unless package.meta_package?
      true

    rescue VersionConflict => e
      ui.puts e.message
      rollback
      ui.abort "installation failed"

    rescue => e
      rollback
      raise e
    end
  end
end

#install_dependencies(package) ⇒ Object



58
59
60
61
62
63
# File 'lib/rip/installer.rb', line 58

def install_dependencies(package)
  package.dependencies.each do |dependency|
    success = install(dependency, package)
    package.run_hook(:dependency_installed, dependency, success)
  end
end

#managerObject



12
13
14
# File 'lib/rip/installer.rb', line 12

def manager
  PackageManager.new
end

#rakebinObject



123
124
125
# File 'lib/rip/installer.rb', line 123

def rakebin
  ENV['RAKEBIN'] || 'rake'
end

#rollbackObject



90
91
92
93
94
95
# File 'lib/rip/installer.rb', line 90

def rollback
  @installed.values.each do |package|
    uninstall(package)
    cleanup(package)
  end
end

#uiObject



127
128
129
# File 'lib/rip/installer.rb', line 127

def ui
  Rip.ui
end

#uninstall(package, remove_dependencies = false) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rip/installer.rb', line 97

def uninstall(package, remove_dependencies = false)
  packages = [package]

  if remove_dependencies
    packages.concat manager.packages_that_depend_on(package.name)
  end

  Dir.chdir Rip::Env.active_dir do
    packages.each do |package|
      begin
        next if @uninstalled[package.name]
        @uninstalled[package.name] = true

        package.files.each do |file|
          FileUtils.rm_rf file
        end

        manager.remove_package(package)
      rescue => e
        ui.puts e.message
        next
      end
    end
  end
end