class Easymon::Checklist
Attributes
items[RW]
results[RW]
Public Class Methods
new(items={})
click to toggle source
# File lib/easymon/checklist.rb, line 11 def initialize(items={}) self.items = items self.results = {} end
Public Instance Methods
as_json(*args)
click to toggle source
# File lib/easymon/checklist.rb, line 47 def as_json(*args) to_hash end
check()
click to toggle source
# File lib/easymon/checklist.rb, line 16 def check self.results = items.inject({}) do |hash, (name, check)| check_result = [] timing = Benchmark.realtime { check_result = check[:check].check } hash[name] = Easymon::Result.new(check_result, timing, check[:critical]) hash end [self.success?, self.to_s] end
fetch(name)
click to toggle source
The following method could be implemented as a def_delegator by extending Forwardable, but since we want to catch IndexError and raise Easymon::NoSuchCheck, we’ll be explicit here.
# File lib/easymon/checklist.rb, line 64 def fetch(name) items.fetch(name) rescue IndexError raise NoSuchCheck, "No check named '#{name}'" end
response_status()
click to toggle source
# File lib/easymon/checklist.rb, line 56 def response_status success? ? :ok : :service_unavailable end
success?()
click to toggle source
# File lib/easymon/checklist.rb, line 51 def success? return false if results.empty? results.values.all?(&:success?) end
timing()
click to toggle source
# File lib/easymon/checklist.rb, line 26 def timing results.values.map{|r| r.timing}.inject(0, :+) end
to_hash()
click to toggle source
# File lib/easymon/checklist.rb, line 39 def to_hash combined = {:timing => Easymon.timing_to_ms(timing)} results.each do |name, result| combined[name] = result.to_hash end combined end
to_s()
click to toggle source
# File lib/easymon/checklist.rb, line 34 def to_s results.map{|name, result| "#{name}: #{result.to_s}"}.join("\n") + "\n - Total Time - " + Easymon.timing_to_ms(self.timing) + "ms" end
to_text()
click to toggle source
# File lib/easymon/checklist.rb, line 30 def to_text to_s end