Class: Flu::Event
- Inherits:
-
Object
- Object
- Flu::Event
- Defined in:
- lib/flu-rails/event.rb
Constant Summary collapse
- ROUTING_KEY_MAX_LENGTH =
255
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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flu-rails/event.rb', line 10 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.
8 9 10 |
# File 'lib/flu-rails/event.rb', line 8 def data @data end |
Instance Method Details
#emitter ⇒ Object
53 54 55 |
# File 'lib/flu-rails/event.rb', line 53 def emitter @meta[:emitter] end |
#id ⇒ Object
41 42 43 |
# File 'lib/flu-rails/event.rb', line 41 def id @meta[:id] end |
#kind ⇒ Object
61 62 63 |
# File 'lib/flu-rails/event.rb', line 61 def kind @meta[:kind] end |
#mark_as_replayed ⇒ Object
49 50 51 |
# File 'lib/flu-rails/event.rb', line 49 def mark_as_replayed @meta[:status] = :replayed end |
#name ⇒ Object
65 66 67 |
# File 'lib/flu-rails/event.rb', line 65 def name @meta[:name] end |
#status ⇒ Object
69 70 71 |
# File 'lib/flu-rails/event.rb', line 69 def status @meta[:status] end |
#timestamp ⇒ Object
57 58 59 |
# File 'lib/flu-rails/event.rb', line 57 def @meta[:timestamp] end |
#timestamp=(new_timestamp) ⇒ Object
45 46 47 |
# File 'lib/flu-rails/event.rb', line 45 def () @meta[:timestamp] = end |
#to_json(options = nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/flu-rails/event.rb', line 34 def to_json(=nil) JSON.dump({ meta: @meta, data: map_complex_object(@data) }) end |
#to_routing_key ⇒ Object
29 30 31 32 |
# File 'lib/flu-rails/event.rb', line 29 def to_routing_key prefix = "#{@meta[:status]}.#{@meta[:emitter]}.#{@meta[:kind]}." "#{prefix}#{routing_key_name(prefix.length)}" end |