Class: Guard::Puppet::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/puppet/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
16
17
# File 'lib/guard/puppet/runner.rb', line 11

def initialize(options)
  @options = {
    :verbose => true,
    :manifest => 'manifests/site.pp'
  }.merge(options)

end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/guard/puppet/runner.rb', line 9

def options
  @options
end

Instance Method Details

#command_line_paramsObject



48
49
50
51
52
53
54
# File 'lib/guard/puppet/runner.rb', line 48

def command_line_params
  command = [ "apply", %{--confdir="#{Dir.pwd}"} ]
  command << "-v" if @options[:verbose]
  command << "-d" if @options[:debug]
  command << @options[:manifest] if @options[:manifest]
  command
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/guard/puppet/runner.rb', line 19

def run
  messages = ::Puppet::Util::Log.newdestination(:guard)

  begin
    maybe_bundle_with_env do
      # TODO: hack, untested, needed to avoid:
      #
      #"Error: Could not initialize global default settings:
      #  Attempting to initialize global default settings more than once!"
      ::Puppet.settings.send(:clear_everything_for_tests)

      ::Puppet::Util::CommandLine.new('puppet', command_line_params).execute
    end
    0
  rescue SystemExit => e
    if e.status == 0
      if messages.has_failed?
        1
      else
        0
      end
    else
      e.status
    end
  ensure
    ::Puppet::Util::Log.close(:guard)
  end
end