Class: EventMeter::EventPayload
- Inherits:
-
Object
- Object
- EventMeter::EventPayload
- Defined in:
- lib/event_meter/event_payload.rb
Instance Attribute Summary collapse
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .build(name, params:, status: nil, started_at: nil, duration_ms: nil) ⇒ Object
- .load(hash) ⇒ Object
- .stringify(hash) ⇒ Object
Instance Method Summary collapse
-
#initialize(name:, params:, status:, started_at:, duration_ms:) ⇒ EventPayload
constructor
A new instance of EventPayload.
- #started_ms ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(name:, params:, status:, started_at:, duration_ms:) ⇒ EventPayload
Returns a new instance of EventPayload.
32 33 34 35 36 37 38 39 40 |
# File 'lib/event_meter/event_payload.rb', line 32 def initialize(name:, params:, status:, started_at:, duration_ms:) now = Time.now.utc @name = normalize_name(name) @status = normalize_status(status || "success") @started_at = parse_time(started_at || now) @duration_ms = integer_or_nil(duration_ms) @params = stringify(params) end |
Instance Attribute Details
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms.
8 9 10 |
# File 'lib/event_meter/event_payload.rb', line 8 def duration_ms @duration_ms end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/event_meter/event_payload.rb', line 8 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/event_meter/event_payload.rb', line 8 def params @params end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
8 9 10 |
# File 'lib/event_meter/event_payload.rb', line 8 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/event_meter/event_payload.rb', line 8 def status @status end |
Class Method Details
.build(name, params:, status: nil, started_at: nil, duration_ms: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/event_meter/event_payload.rb', line 10 def self.build(name, params:, status: nil, started_at: nil, duration_ms: nil) new( name: name, params: params, status: status, started_at: started_at, duration_ms: duration_ms ) end |
.load(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/event_meter/event_payload.rb', line 20 def self.load(hash) hash = stringify(hash) new( name: hash.fetch("name"), params: hash.fetch("params", {}), status: hash["status"], started_at: hash.fetch("started_at"), duration_ms: hash["duration_ms"] ) end |
Instance Method Details
#started_ms ⇒ Object
56 57 58 |
# File 'lib/event_meter/event_payload.rb', line 56 def started_ms (started_at.to_f * 1000).to_i end |
#to_h ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/event_meter/event_payload.rb', line 42 def to_h { "name" => name, "status" => status, "started_at" => started_at.iso8601(6), "duration_ms" => duration_ms, "params" => params }.delete_if { |_key, value| value.nil? || value == {} } end |
#to_json(*args) ⇒ Object
52 53 54 |
# File 'lib/event_meter/event_payload.rb', line 52 def to_json(*args) to_h.to_json(*args) end |