Class: Downstream::DataEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/downstream/data_event.rb

Constant Summary

Constants inherited from Event

Event::RESERVED_ATTRIBUTES

Class Attribute Summary collapse

Attributes inherited from Event

#data, #errors, #event_id

Instance Method Summary collapse

Methods inherited from Event

#==, attributes, define, defined_attributes, human_attribute_name, i18n_scope, #inspect, lookup_ancestors, #read_attribute_for_validation, #to_global_id, #type

Constructor Details

#initialize(event_id: nil, **attrs) ⇒ DataEvent

Returns a new instance of DataEvent.



18
19
20
21
22
# File 'lib/downstream/data_event.rb', line 18

def initialize(event_id: nil, **attrs)
  @event_id = event_id || SecureRandom.hex(10)
  @data = self.class.data_class.new(**attrs)
  freeze
end

Class Attribute Details

.data_classObject



8
9
10
11
12
# File 'lib/downstream/data_event.rb', line 8

def data_class
  return @data_class if @data_class

  @data_class = superclass.data_class
end

Instance Method Details

#to_hObject



24
25
26
27
28
29
30
# File 'lib/downstream/data_event.rb', line 24

def to_h
  {
    type:,
    event_id:,
    data: data.to_h.freeze
  }.freeze
end