Class: Bosh::Monitor::Events::Base
- Inherits:
-
Object
- Object
- Bosh::Monitor::Events::Base
- Defined in:
- lib/bosh/monitor/events/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(error) ⇒ Object
- #error_message ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
38 39 40 41 42 43 44 45 46 47 48 |
# 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/bosh/monitor/events/base.rb', line 8 def attributes @attributes end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/bosh/monitor/events/base.rb', line 9 def errors @errors end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/bosh/monitor/events/base.rb', line 4 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
7 8 9 |
# File 'lib/bosh/monitor/events/base.rb', line 7 def kind @kind end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/bosh/monitor/events/base.rb', line 6 def logger @logger end |
Class Method Details
.create(kind, attributes = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bosh/monitor/events/base.rb', line 11 def self.create!(kind, attributes = {}) event = create(kind, attributes) if !event.valid? raise InvalidEvent, event. end event end |
Instance Method Details
#add_error(error) ⇒ Object
50 51 52 |
# File 'lib/bosh/monitor/events/base.rb', line 50 def add_error(error) @errors << error end |
#error_message ⇒ Object
59 60 61 |
# File 'lib/bosh/monitor/events/base.rb', line 59 def @errors.to_a.join(", ") end |
#valid? ⇒ Boolean
54 55 56 57 |
# File 'lib/bosh/monitor/events/base.rb', line 54 def valid? validate @errors.empty? end |