Class: DataCollector::Runner

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/data_collector/runner.rb

Instance Method Summary collapse

Methods included from Core

config, error, filter, input, log, logger, output, pipeline, rules, rules_ng

Constructor Details

#initialize(logger = Logger.new(STDOUT)) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
# File 'lib/data_collector/runner.rb', line 7

def initialize(logger = Logger.new(STDOUT))
  Encoding.default_external = 'UTF-8'
  @logger = logger
end

Instance Method Details

#run(rule_file_name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/data_collector/runner.rb', line 12

def run(rule_file_name = nil)
  @time_start = Time.now
  prg = self
  if block_given?
    a = Class.new do
      include DataCollector::Core
    end.new

    yield a
  elsif !rule_file_name.nil?
    prg.instance_eval(File.read(rule_file_name))
  else
    @logger.error('Please supply a block or file')
  end

  prg
rescue Error => e
  puts e.message
  puts e.backtrace.join("\n")
ensure
  @logger.info("Finished in #{((Time.now - @time_start)*1000).to_i} ms")
end