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
# File 'lib/sprinkle/installers/installer.rb', line 6

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



32
33
34
35
36
37
38
# File 'lib/sprinkle/installers/installer.rb', line 32

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

Instance Method Details

#defaults(deployment) ⇒ Object



12
13
14
15
16
# File 'lib/sprinkle/installers/installer.rb', line 12

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sprinkle/installers/installer.rb', line 18

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