Class: ActionPubsub::Event

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model, ActiveModel::AttributeMethods
Defined in:
lib/action_pubsub/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(topic:, record: nil, context: nil, **options) ⇒ Event

attributes have to be set for purposes of marshaling



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/action_pubsub/event.rb', line 19

def initialize(topic:, record:nil, context: nil, **options)
  self[:topic] = topic
  self[:action] = topic.split("/").pop.to_sym
  self[:meta] = options[:meta] || {}
  self[:name] = topic
  self[:record] = record
  self[:id] = ::SecureRandom.hex
  self[:subject] = options[:subject] || record.try(:class).try(:name)
  self[:context] = context if context
  self[:occured_at] ||= ::Time.now.to_i
end