Class: Niman::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/niman/provisioner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(installer, filehandler, shell, instructions) ⇒ Provisioner

Returns a new instance of Provisioner.



7
8
9
10
11
12
# File 'lib/niman/provisioner.rb', line 7

def initialize(installer, filehandler, shell, instructions)
  @installer    = installer
  @filehandler  = filehandler
  @shell        = shell
  @instructions = Array(instructions)
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



5
6
7
# File 'lib/niman/provisioner.rb', line 5

def instructions
  @instructions
end

Instance Method Details

#errorsObject



18
19
20
# File 'lib/niman/provisioner.rb', line 18

def errors
  @instructions.map(&:errors).flatten.join("\n")
end

#runObject

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/niman/provisioner.rb', line 22

def run
  raise Niman::ConfigError, self.errors unless self.valid?
  @instructions.each do |instruction|
    yield(instruction) if block_given?
    if is_file(instruction)
      @filehandler.run(instruction)
    elsif instruction.respond_to?(:command)
      command(instruction)
    else
      @installer.install(instruction)
    end

    if instruction.respond_to?(:files)
      custom_package_files(instruction)
    end
    if instruction.respond_to?(:commands)
      custom_package_exec(instruction)
    end
  end
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/niman/provisioner.rb', line 14

def valid?
  @instructions.all?(&:valid?)
end