Class: SandthornDriverSequel2::FileOutputWrapper::Events

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_file, sequence_number, delimiter: ',') ⇒ Events

Returns a new instance of Events.



7
8
9
10
11
# File 'lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb', line 7

def initialize event_file, sequence_number, delimiter: ','
  @event_file = event_file
  @sequence_number = sequence_number
  @delimiter = delimiter
end

Instance Method Details

#events(sequel) ⇒ Object



13
14
15
16
# File 'lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb', line 13

def events sequel
  @sequel = sequel
  self
end

#flushObject



33
34
35
# File 'lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb', line 33

def flush
  @event_file.flush
end

#insert(*args) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb', line 18

def insert *args
  args.each do |event|
    @sequence_number += 1
    event_data = String.new("#{event[:event_data]}")
    event_data = " #{event_data}" if event_data =~ /^[\n\r]/
    @event_file.puts "#{@sequence_number}#{@delimiter}#{event[:aggregate_id]}#{@delimiter}#{event[:aggregate_version]}#{@delimiter}#{event[:aggregate_type]}#{@delimiter}#{event[:event_name]}#{@delimiter}#{event_data}#{@delimiter}#{event[:timestamp]}"
  end
end

#save(*args) ⇒ Object



29
30
31
# File 'lib/sandthorn_driver_sequel_2/file_output_wrappers/events.rb', line 29

def save *args
  @event_file.write args
end