Class: Flu::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/flu-rails/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, emitter, kind, name, data) ⇒ Event

Returns a new instance of Event.

Raises:

  • (ArgumentError)


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

#dataObject (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

#emitterObject



48
49
50
# File 'lib/flu-rails/event.rb', line 48

def emitter
  @meta[:emitter]
end

#idObject



36
37
38
# File 'lib/flu-rails/event.rb', line 36

def id
  @meta[:id]
end

#kindObject



56
57
58
# File 'lib/flu-rails/event.rb', line 56

def kind
  @meta[:kind]
end

#mark_as_replayedObject



44
45
46
# File 'lib/flu-rails/event.rb', line 44

def mark_as_replayed
  @meta[:status] = :replayed
end

#nameObject



60
61
62
# File 'lib/flu-rails/event.rb', line 60

def name
  @meta[:name]
end

#statusObject



64
65
66
# File 'lib/flu-rails/event.rb', line 64

def status
  @meta[:status]
end

#timestampObject



52
53
54
# File 'lib/flu-rails/event.rb', line 52

def timestamp
  @meta[:timestamp]
end

#timestamp=(new_timestamp) ⇒ Object



40
41
42
# File 'lib/flu-rails/event.rb', line 40

def timestamp=(new_timestamp)
  @meta[:timestamp] = new_timestamp
end

#to_json(options = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/flu-rails/event.rb', line 29

def to_json(options=nil)
  JSON.dump({
    meta: @meta,
    data: map_complex_object(@data)
  })
end

#to_routing_keyObject



25
26
27
# File 'lib/flu-rails/event.rb', line 25

def to_routing_key
  "#{@meta[:status]}.#{@meta[:emitter]}.#{@meta[:kind]}.#{@meta[:name]}"
end