Class: LogMaster::Director

Inherits:
Object
  • Object
show all
Defined in:
lib/log_master/director.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, options = {}) ⇒ Director

Returns a new instance of Director.



12
13
14
15
16
17
18
19
20
# File 'lib/log_master/director.rb', line 12

def initialize(files, options={})
  @options = options
  @options[:file]       ||= 'config/log_master.rb'
  
  @reports = {}
  
  load_configuration
  create_log_files(files)
end

Instance Attribute Details

#logsObject

Returns the value of attribute logs.



6
7
8
# File 'lib/log_master/director.rb', line 6

def logs
  @logs
end

#reportsObject

Returns the value of attribute reports.



6
7
8
# File 'lib/log_master/director.rb', line 6

def reports
  @reports
end

Class Method Details

.execute(files, options = {}) ⇒ Object



8
9
10
# File 'lib/log_master/director.rb', line 8

def self.execute(files, options={})
  new(files, options).run
end

Instance Method Details

#aggregate!Object



40
41
42
43
44
45
46
47
# File 'lib/log_master/director.rb', line 40

def aggregate!
  logs.each do |l|
    l.analyze.each do |name, value|
      @reports[name] ||= 0
      @reports[name] += value
    end
  end
end

#load_configurationObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/log_master/director.rb', line 27

def load_configuration
  require @options[:file] if File.exists?(@options[:file])

  # config = File.read(@options[:file])
  # eval(config)
  
  if Configuration.configured?
    @configuration = Configuration.instance
  else
    raise "[fail] LogMaster is not configured"
  end
end

#runObject



22
23
24
25
# File 'lib/log_master/director.rb', line 22

def run
  aggregate!
  send_email
end

#send_emailObject



53
54
55
# File 'lib/log_master/director.rb', line 53

def send_email
  Notifier.deliver_update_notification(successful?, @reports, @logs)
end

#successful?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/log_master/director.rb', line 49

def successful?
  @configuration.failure_conditions.all? {|fc| @reports.fetch(fc, 0) == 0} && @logs.all? {|l| l.valid?}
end