Class: Pot::Installer

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

Overview

Based on … Copyright © 2008-2009 Marcus Crafter [email protected]

The base class which all installers must subclass, this class makes sure all installers share some general features, which are outlined below.

Pre/Post Installation Hooks

With all installation methods you have the ability to specify multiple pre/post installation hooks. This gives you the ability to specify commands to run before and after an installation takes place. All commands by default are sudo’d so there is no need to include “sudo” in the command itself. There are three ways to specify a pre/post hook.

First, a single command:

pre :install, 'echo "Hello, World!"'
post :install, 'rm -rf /'

Second, an array of commands:

commands = ['echo "First"', 'echo "Then Another"']
pre :install, commands
post :install, commands

Third, a block which returns either a single or multiple commands:

pre :install do
  amount = 7 * 3
  "echo 'Before we install, lets plant #{amount} magic beans...'"
end
post :install do
  ['echo "Now... let's hope they sprout!", 'echo "Indeed they have!"']
end

Other Pre/Post Hooks

Some installation methods actually grant you more fine grained control of when commands are run rather than a blanket pre :install or post :install. If this is the case, it will be documented on the installation method’s corresponding documentation page.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package, options = {}, &block) ⇒ Installer

:nodoc:



47
48
49
50
51
52
53
# File 'lib/pot/installer.rb', line 47

def initialize(package, options = {}, &block) #:nodoc:
  @package = package
  @options = options
  @pre = {}
  @post = {}
  self.instance_eval(&block) if block
end

Instance Attribute Details

#actorObject

:nodoc:



45
46
47
# File 'lib/pot/installer.rb', line 45

def actor
  @actor
end

#optionsObject

:nodoc:



45
46
47
# File 'lib/pot/installer.rb', line 45

def options
  @options
end

#packageObject

:nodoc:



45
46
47
# File 'lib/pot/installer.rb', line 45

def package
  @package
end

#post(stage, *commands) ⇒ Object

:nodoc:



45
46
47
# File 'lib/pot/installer.rb', line 45

def post
  @post
end

#pre(stage, *commands) ⇒ Object

:nodoc:



45
46
47
# File 'lib/pot/installer.rb', line 45

def pre
  @pre
end

Instance Method Details

#archives(archives) ⇒ Object



71
72
73
# File 'lib/pot/installer.rb', line 71

def archives(archives)
  @options[:archives] = archives
end

#builds(builds) ⇒ Object



75
76
77
# File 'lib/pot/installer.rb', line 75

def builds(builds)
  @options[:builds] = builds
end

#commandsObject

More complicated installers that have different stages, and require pre/post commands within stages can override commands and take complete control of the install command sequence construction (eg. source based installer).



95
96
97
98
# File 'lib/pot/installer.rb', line 95

def commands
  commands = pre_commands(:install) + [ install_commands ] + post_commands(:install)
  commands.flatten
end

#prefix(prefix) ⇒ Object



67
68
69
# File 'lib/pot/installer.rb', line 67

def prefix(prefix)
  @options[:prefix] = prefix
end

#process(actor) ⇒ Object

:nodoc:



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pot/installer.rb', line 79

def process(actor) #:nodoc:
  if Pot.logger.debug?
    sequence = commands;
    sequence = sequence.join('; ') if sequence.is_a? Array
    Pot.logger.debug "#{@package.name} install sequence: #{sequence}\n"
  end

  unless Pot.config.testing?
    Pot.logger.info "--> Installing #{package.name}"
    actor.install(self)
  end
end