Class: EventHub::Event
- Inherits:
-
Object
- Object
- EventHub::Event
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/event_hub/event.rb
Class Attribute Summary collapse
-
.attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
- .attribute(attribute, options = {}) ⇒ Object
- .event(event = nil) ⇒ Object
- .version(version = nil) ⇒ Object
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(hash = {}) ⇒ Event
constructor
A new instance of Event.
- #publish ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Event
Returns a new instance of Event.
10 11 12 13 14 |
# File 'lib/event_hub/event.rb', line 10 def initialize(hash = {}) hash.transform_keys(&:to_s).slice(*self.class.attributes.keys).each do |attr, val| public_send("#{attr}=", val) end end |
Class Attribute Details
.attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
39 40 41 |
# File 'lib/event_hub/event.rb', line 39 def attributes @attributes end |
Class Method Details
.attribute(attribute, options = {}) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/event_hub/event.rb', line 41 def attribute(attribute, = {}) @attributes ||= {} @attributes[attribute.to_s] = attr_accessor(attribute) end |
.event(event = nil) ⇒ Object
28 29 30 31 |
# File 'lib/event_hub/event.rb', line 28 def self.event(event = nil) @event = event.to_s if event @event end |
.version(version = nil) ⇒ Object
33 34 35 36 |
# File 'lib/event_hub/event.rb', line 33 def self.version(version = nil) @version = version if version @version end |
Instance Method Details
#body ⇒ Object
22 23 24 25 26 |
# File 'lib/event_hub/event.rb', line 22 def body self.class.attributes.keys.to_h do |attr| [attr, public_send(attr)] end.to_json end |
#publish ⇒ Object
16 17 18 19 20 |
# File 'lib/event_hub/event.rb', line 16 def publish run_callbacks :publish do EventHub.publish(self) end end |