Class: Orca::Runner
- Inherits:
-
Object
show all
- Defined in:
- lib/orca/runner.rb
Defined Under Namespace
Classes: ValidationFailureError
Instance Method Summary
collapse
Constructor Details
#initialize(node, package, skip_dependancies = false) ⇒ Runner
Returns a new instance of Runner.
2
3
4
5
6
7
8
|
# File 'lib/orca/runner.rb', line 2
def initialize(node, package, skip_dependancies=false)
@node = node
@package = package
@perform = true
@skip_dependancies = skip_dependancies
@log = Orca::Logger.new(@node, package)
end
|
Instance Method Details
#demonstrate(command_name) ⇒ Object
61
62
63
64
65
|
# File 'lib/orca/runner.rb', line 61
def demonstrate(command_name)
@perform = false
execute(command_name)
@perform = true
end
|
#exec(pkg, command_name) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/orca/runner.rb', line 67
def exec(pkg, command_name)
@log.set_package(pkg)
@log.command(command_name)
context = @perform ? Orca::ExecutionContext.new(@node, @log) : Orca::MockExecutionContext.new(@node, @log)
cmds = pkg.command(command_name)
cmds.map {|cmd| context.apply(cmd) }
end
|
#execute(command_name) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/orca/runner.rb', line 17
def execute(command_name)
@log.say packages.map(&:name).join(', ').yellow
packages.each do |pkg|
send(:"execute_#{command_name}", pkg)
end
end
|
#execute_apply(pkg) ⇒ Object
24
25
26
27
28
|
# File 'lib/orca/runner.rb', line 24
def execute_apply(pkg)
return unless should_run?(pkg, :apply)
exec(pkg, :apply)
validate!(pkg)
end
|
#execute_remove(pkg) ⇒ Object
30
31
32
33
|
# File 'lib/orca/runner.rb', line 30
def execute_remove(pkg)
return unless should_run?(pkg, :remove)
exec(pkg, :remove)
end
|
#execute_validate(pkg) ⇒ Object
35
36
37
|
# File 'lib/orca/runner.rb', line 35
def execute_validate(pkg)
validate!(pkg)
end
|
#is_valid?(pkg) ⇒ Boolean
56
57
58
59
|
# File 'lib/orca/runner.rb', line 56
def is_valid?(pkg)
results = exec(pkg, :validate)
results.all?
end
|
#packages ⇒ Object
10
11
12
13
14
15
|
# File 'lib/orca/runner.rb', line 10
def packages
return [@package] if @skip_dependancies
resolver = Orca::Resolver.new(@package)
resolver.resolve
resolver.packages
end
|
#should_run?(pkg, command_name) ⇒ Boolean
39
40
41
42
43
44
45
46
47
|
# File 'lib/orca/runner.rb', line 39
def should_run?(pkg, command_name)
return false unless pkg.provides_command?(command_name)
return true unless @perform
return true unless command_name == :apply || command_name == :remove
return true unless pkg.provides_command?(:validate)
is_present = is_valid?(pkg)
return !is_present if command_name == :apply
return is_present
end
|
#validate!(pkg) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/orca/runner.rb', line 49
def validate!(pkg)
return true unless @perform
return unless pkg.provides_command?(:validate)
return if is_valid?(pkg)
raise ValidationFailureError.new(@node, pkg)
end
|