Class: Sprinkle::Installers::Installer

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/sprinkle/installers/installer.rb

Overview

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)

Methods included from Configurable

#assert_delivery, #defaults, #method_missing, #option?

Constructor Details

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

:nodoc:



46
47
48
49
50
51
# File 'lib/sprinkle/installers/installer.rb', line 46

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sprinkle::Configurable

Instance Attribute Details

- (Object) delivery

:nodoc:



44
45
46
# File 'lib/sprinkle/installers/installer.rb', line 44

def delivery
  @delivery
end

- (Object) options

:nodoc:



44
45
46
# File 'lib/sprinkle/installers/installer.rb', line 44

def options
  @options
end

- (Object) package

:nodoc:



44
45
46
# File 'lib/sprinkle/installers/installer.rb', line 44

def package
  @package
end

- (Object) post(stage, *commands)

:nodoc:



44
45
46
# File 'lib/sprinkle/installers/installer.rb', line 44

def post
  @post
end

- (Object) pre(stage, *commands)

:nodoc:



44
45
46
# File 'lib/sprinkle/installers/installer.rb', line 44

def pre
  @pre
end

Instance Method Details

- (Object) process(roles)

:nodoc:



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sprinkle/installers/installer.rb', line 65

def process(roles) #:nodoc:
  assert_delivery

  if logger.debug?
    sequence = install_sequence; sequence = sequence.join('; ') if sequence.is_a? Array
    logger.debug "#{@package.name} install sequence: #{sequence} for roles: #{roles}\n"
  end

  unless Sprinkle::OPTIONS[:testing]
    logger.info "--> Installing #{package.name} for roles: #{roles}"
    @delivery.process(@package.name, install_sequence, roles)
  end
end