Class: LogMaster::Director
- Inherits:
-
Object
- Object
- LogMaster::Director
- Defined in:
- lib/log_master/director.rb
Instance Attribute Summary collapse
-
#logs ⇒ Object
Returns the value of attribute logs.
-
#reports ⇒ Object
Returns the value of attribute reports.
Class Method Summary collapse
Instance Method Summary collapse
- #aggregate! ⇒ Object
-
#initialize(files, options = {}) ⇒ Director
constructor
A new instance of Director.
- #load_configuration ⇒ Object
- #run ⇒ Object
- #send_email ⇒ Object
- #successful? ⇒ Boolean
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[:file] ||= 'config/log_master.rb' @reports = {} load_configuration create_log_files(files) end |
Instance Attribute Details
#logs ⇒ Object
Returns the value of attribute logs.
6 7 8 |
# File 'lib/log_master/director.rb', line 6 def logs @logs end |
#reports ⇒ Object
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, ={}) new(files, ).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_configuration ⇒ Object
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 |
#run ⇒ Object
22 23 24 25 |
# File 'lib/log_master/director.rb', line 22 def run aggregate! send_email end |
#send_email ⇒ Object
53 54 55 |
# File 'lib/log_master/director.rb', line 53 def send_email Notifier.deliver_update_notification(successful?, @reports, @logs) end |
#successful? ⇒ 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 |