Class: Puppi::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/puppi/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Action

Returns a new instance of Action.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/puppi/action.rb', line 5

def initialize (options)
  @loader = Puppi::Loader.new
  @actions = [ 'check', 'log', 'info' ]
  if options[:puppi_module].nil?
    @puppi_module = nil
  else
    @puppi_module = options[:puppi_module].to_s
  end
  if @actions.include? options[:action].to_s
    execute options[:action].to_s
  else
    raise "No Action Found"
  end
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



3
4
5
# File 'lib/puppi/action.rb', line 3

def output
  @output
end

#puppi_moduleObject (readonly)

Returns the value of attribute puppi_module.



3
4
5
# File 'lib/puppi/action.rb', line 3

def puppi_module
  @puppi_module
end

Instance Method Details

#execute(action) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppi/action.rb', line 20

def execute action
  @datafiles = @loader.load_all('data', @puppi_module)
  @output = Array.new
  @datafiles.each do |datafile|
    @loaded_datafile = @loader.load_datafile(datafile)
    datafile_helper = datafile.split("_")[0]
    module_helper = datafile.split("_")[1]
    @helper_commands = @loader.load_helperfile datafile_helper, action
    return nil unless not @helper_commands.nil?
    @helper_commands.each do |command|
      @output << (run_command command, module_helper)
    end
  end
end