class Bosh::Monitor::Events::Base
Attributes
attributes[R]
errors[R]
id[RW]
kind[R]
logger[R]
Public Class Methods
create(kind, attributes = {})
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 19 def self.create(kind, attributes = {}) if !attributes.kind_of?(Hash) raise InvalidEvent, "Cannot create event from #{attributes.class}" end case kind.to_s when "heartbeat" klass = Bhm::Events::Heartbeat when "alert" klass = Bhm::Events::Alert else raise InvalidEvent, "Cannot find '#{kind}' event handler" end event = klass.new(attributes) event.id = SecureRandom.uuid if event.id.nil? event end
create!(kind, attributes = {})
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 11 def self.create!(kind, attributes = {}) event = create(kind, attributes) if !event.valid? raise InvalidEvent, event.error_message end event end
new(attributes = {})
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 38 def initialize(attributes = {}) @attributes = {} @kind = :unknown attributes.each_pair do |k, v| @attributes[k.to_s] = v end @logger = Bhm.logger @errors = Set.new end
Public Instance Methods
add_error(error)
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 50 def add_error(error) @errors << error end
error_message()
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 59 def error_message @errors.to_a.join(", ") end
valid?()
click to toggle source
# File lib/bosh/monitor/events/base.rb, line 54 def valid? validate @errors.empty? end