Class: Rake::Builder::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/builder/installer.rb

Instance Method Summary collapse

Instance Method Details

#install(source_pathname, destination_path) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rake/builder/installer.rb', line 5

def install(source_pathname, destination_path)
  ensure_file_exists source_pathname
  raise "The path '#{destination_path}' does not exist" unless File.exist?(destination_path)
  raise "'#{destination_path}' is not a directory" unless File.directory?(destination_path)
  ensure_directory_writable destination_path, "Cannot copy files to the directory '#{destination_path}'"
  filename = File.basename(source_pathname)
  destination_pathname = File.join(destination_path, filename)
  if File.file?(destination_pathname) and not File.writable?(destination_pathname)
    raise "The file '#{destination_pathname}' cannot be overwritten"
  end

  FileUtils.copy_file source_pathname, destination_path
end

#uninstall(installed_pathname) ⇒ Object


19
20
21
22
23
# File 'lib/rake/builder/installer.rb', line 19

def uninstall(installed_pathname)
  return unless File.exist?(installed_pathname)
  ensure_directory_writable File.dirname(installed_pathname)
  File.unlink installed_pathname
end