Class: Sprinkle::Installers::Installer

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

Direct Known Subclasses

Apt, Gem, Rake, Rpm, Source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



6
7
8
9
10
11
# File 'lib/sprinkle/installers/installer.rb', line 6

def initialize(package, options = {}, &block)
  @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

#method_missing(sym, *args, &block) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/sprinkle/installers/installer.rb', line 43

def method_missing(sym, *args, &block)
  unless args.empty? # mutate if not set
    @options[sym] = *args unless @options[sym]
  end

  @options[sym] || @package.send(sym, *args, &block) # try the parents options if unknown
end

Instance Attribute Details

#deliveryObject

Returns the value of attribute delivery.



4
5
6
# File 'lib/sprinkle/installers/installer.rb', line 4

def delivery
  @delivery
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/sprinkle/installers/installer.rb', line 4

def options
  @options
end

#packageObject

Returns the value of attribute package.



4
5
6
# File 'lib/sprinkle/installers/installer.rb', line 4

def package
  @package
end

#post(stage, *commands) ⇒ Object

Returns the value of attribute post.



4
5
6
# File 'lib/sprinkle/installers/installer.rb', line 4

def post
  @post
end

#pre(stage, *commands) ⇒ Object

Returns the value of attribute pre.



4
5
6
# File 'lib/sprinkle/installers/installer.rb', line 4

def pre
  @pre
end

Instance Method Details

#defaults(deployment) ⇒ Object



23
24
25
26
27
# File 'lib/sprinkle/installers/installer.rb', line 23

def defaults(deployment)
  defaults = deployment.defaults[self.class.name.split(/::/).last.downcase.to_sym]
  self.instance_eval(&defaults) if defaults
  @delivery = deployment.style
end

#process(roles) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sprinkle/installers/installer.rb', line 29

def process(roles)
  raise 'Unknown command delivery target' unless @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