Class: Technologic::Event

Inherits:
Object
  • Object
show all
Includes:
ShortCircuIt
Defined in:
lib/technologic/event.rb

Constant Summary collapse

LOGGABLE_DURATION_THRESHOLD_MS =
0.04

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, started, finished, payload) ⇒ Event

Returns a new instance of Event.



11
12
13
14
15
# File 'lib/technologic/event.rb', line 11

def initialize(name, started, finished, payload)
  @name = name
  @duration = finished - started
  @payload = payload
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



9
10
11
# File 'lib/technologic/event.rb', line 9

def duration
  @duration
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/technologic/event.rb', line 9

def name
  @name
end

Instance Method Details

#dataObject



17
18
19
20
21
22
23
24
25
# File 'lib/technologic/event.rb', line 17

def data
  duration_in_ms = duration * 1000

  {}.tap do |hash|
    hash.merge!(@payload)
    hash[:event] = name
    hash[:duration] = ConfigOptions.log_duration_in_ms ? duration_in_ms : duration if duration_in_ms > LOGGABLE_DURATION_THRESHOLD_MS
  end
end