Class: Hey::Pubsub::Event
- Inherits:
-
Object
- Object
- Hey::Pubsub::Event
- Defined in:
- lib/hey/pubsub/event.rb
Instance Attribute Summary collapse
- #ended_at ⇒ Object
- #metadata ⇒ Object
-
#name ⇒ Object
Returns the value of attribute name.
- #started_at ⇒ Object
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(name:, started_at: nil, ended_at: nil, metadata: {}) ⇒ Event
constructor
A new instance of Event.
- #to_h ⇒ Object
Constructor Details
#initialize(name:, started_at: nil, ended_at: nil, metadata: {}) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 |
# File 'lib/hey/pubsub/event.rb', line 5 def initialize(name:, started_at: nil, ended_at: nil, metadata: {}) @name = name @started_at = started_at @ended_at = ended_at @metadata = end |
Instance Attribute Details
#ended_at ⇒ Object
25 26 27 28 |
# File 'lib/hey/pubsub/event.rb', line 25 def ended_at return if @ended_at.nil? @ended_at.strftime("%Y-%m-%dT%H:%M:%S.%L") end |
#metadata ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/hey/pubsub/event.rb', line 30 def = Hey::ThreadCargo.contexts.reverse.map(&:to_h).reduce(Hash.new, :merge) merged_data = .merge(@metadata) hash = Hey::SanitizedHash.new(merged_data).to_h hash.delete(:sanitize) hash end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/hey/pubsub/event.rb', line 3 def name @name end |
#started_at ⇒ Object
20 21 22 23 |
# File 'lib/hey/pubsub/event.rb', line 20 def started_at return if @started_at.nil? @started_at.strftime("%Y-%m-%dT%H:%M:%S.%L") end |
Instance Method Details
#duration ⇒ Object
38 39 40 41 |
# File 'lib/hey/pubsub/event.rb', line 38 def duration return if @ended_at.nil? || @started_at.nil? 1000.0 * (@ended_at - @started_at) end |
#to_h ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/hey/pubsub/event.rb', line 12 def to_h hash = { uuid: Hey::ThreadCargo.uuid, name: name, metadata: } hash[:started_at] = started_at unless started_at.nil? hash[:ended_at] = ended_at unless ended_at.nil? hash[:duration] = duration unless duration.nil? hash end |