Class: Flu::Event
- Inherits:
-
Object
- Object
- Flu::Event
- Defined in:
- lib/flu-rails/event.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #emitter ⇒ Object
- #id ⇒ Object
-
#initialize(uuid, emitter, kind, name, data) ⇒ Event
constructor
A new instance of Event.
- #kind ⇒ Object
- #mark_as_replayed ⇒ Object
- #name ⇒ Object
- #status ⇒ Object
- #timestamp ⇒ Object
- #timestamp=(new_timestamp) ⇒ Object
- #to_json(options = nil) ⇒ Object
- #to_routing_key ⇒ Object
Constructor Details
#initialize(uuid, emitter, kind, name, data) ⇒ Event
Returns a new instance of Event.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/flu-rails/event.rb', line 8 def initialize(uuid, emitter, kind, name, data) raise ArgumentError, "uuid must not be nil" if uuid.nil? raise ArgumentError, "emitter must not be nil nor empty" if emitter.nil? || emitter.length == 0 raise ArgumentError, "kind must not be nil nor empty" if kind.nil? || kind.length == 0 raise ArgumentError, "name must not be nil nor empty" if name.nil? || name.length == 0 @meta = { id: uuid, name: name, emitter: emitter, timestamp: Time.now.utc, kind: kind, status: :new } @data = data || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/flu-rails/event.rb', line 6 def data @data end |
Instance Method Details
#emitter ⇒ Object
48 49 50 |
# File 'lib/flu-rails/event.rb', line 48 def emitter @meta[:emitter] end |
#id ⇒ Object
36 37 38 |
# File 'lib/flu-rails/event.rb', line 36 def id @meta[:id] end |
#kind ⇒ Object
56 57 58 |
# File 'lib/flu-rails/event.rb', line 56 def kind @meta[:kind] end |
#mark_as_replayed ⇒ Object
44 45 46 |
# File 'lib/flu-rails/event.rb', line 44 def mark_as_replayed @meta[:status] = :replayed end |
#name ⇒ Object
60 61 62 |
# File 'lib/flu-rails/event.rb', line 60 def name @meta[:name] end |
#status ⇒ Object
64 65 66 |
# File 'lib/flu-rails/event.rb', line 64 def status @meta[:status] end |
#timestamp ⇒ Object
52 53 54 |
# File 'lib/flu-rails/event.rb', line 52 def @meta[:timestamp] end |
#timestamp=(new_timestamp) ⇒ Object
40 41 42 |
# File 'lib/flu-rails/event.rb', line 40 def () @meta[:timestamp] = end |
#to_json(options = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/flu-rails/event.rb', line 29 def to_json(=nil) JSON.dump({ meta: @meta, data: map_complex_object(@data) }) end |
#to_routing_key ⇒ Object
25 26 27 |
# File 'lib/flu-rails/event.rb', line 25 def to_routing_key "#{@meta[:status]}.#{@meta[:emitter]}.#{@meta[:kind]}.#{@meta[:name]}" end |