Class: Rip::Installer
- Inherits:
-
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
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
#installed ⇒ Object
Returns the value of attribute installed.
5
6
7
|
# File 'lib/rip/installer.rb', line 5
def installed
@installed
end
|
Instance Method Details
#cleanup(package) ⇒ Object
89
90
91
|
# File 'lib/rip/installer.rb', line 89
def cleanup(package)
FileUtils.rm_rf package.cache_path unless package.cached?
end
|
#copy_files(package) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rip/installer.rb', line 72
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
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
|
# File 'lib/rip/installer.rb', line 16
def install(package, parent = nil)
if !package.exists?
error = package.name
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.version
ui.abort "can't install #{package} - it has no version"
end
package.fetch
package.unpack
install_dependencies(package)
run_install_hook(package)
copy_files(package)
cleanup(package)
ui.puts "Successfully installed #{package}" unless package.meta_package?
rescue VersionConflict => e
ui.puts e.message
rollback
ui.abort "installation failed"
rescue => e
rollback
raise e
end
end
end
|
#install_dependencies(package) ⇒ Object
57
58
59
60
61
|
# File 'lib/rip/installer.rb', line 57
def install_dependencies(package)
package.dependencies.each do |dependency|
install(dependency, package)
end
end
|
#rollback ⇒ Object
93
94
95
96
97
98
|
# File 'lib/rip/installer.rb', line 93
def rollback
@installed.values.each do |package|
uninstall(package)
cleanup(package)
end
end
|
#run_install_hook(package) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/rip/installer.rb', line 63
def run_install_hook(package)
return unless File.exists? File.join(package.cache_path, 'Rakefile')
Dir.chdir package.cache_path do
ui.puts "running install hook for #{package.name}"
system "rake -s rip:install >& /dev/null"
end
end
|
#ui ⇒ Object
126
127
128
|
# File 'lib/rip/installer.rb', line 126
def ui
Rip.ui
end
|
#uninstall(package, remove_dependencies = false) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/rip/installer.rb', line 100
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
|