Class: Journaled::Writer

Inherits:
Object
  • Object
show all
Defined in:
app/models/journaled/writer.rb

Constant Summary collapse

EVENT_METHOD_NAMES =
%i(
  journaled_schema_name
  journaled_partition_key
  journaled_attributes
  journaled_app_name
  journaled_enqueue_opts
).freeze

Instance Method Summary collapse

Constructor Details

#initialize(journaled_event:) ⇒ Writer

Returns a new instance of Writer.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/journaled/writer.rb', line 10

def initialize(journaled_event:)
  raise "An enqueued event must respond to: #{EVENT_METHOD_NAMES.to_sentence}" unless respond_to_all?(journaled_event, EVENT_METHOD_NAMES)

  unless journaled_event.journaled_schema_name.present? &&
      journaled_event.journaled_partition_key.present? &&
      journaled_event.journaled_attributes.present?
    raise <<~ERROR
      An enqueued event must have a non-nil response to:
        #json_schema_name,
        #partition_key, and
        #journaled_attributes
    ERROR
  end

  @journaled_event = journaled_event
end

Instance Method Details

#journal!Object



27
28
29
30
31
# File 'app/models/journaled/writer.rb', line 27

def journal!
  base_event_json_schema_validator.validate! serialized_event
  json_schema_validator.validate! serialized_event
  Journaled.enqueue!(journaled_delivery, journaled_enqueue_opts)
end