Module: Wal::Watcher::SeparatedEvents

Overview

Include this module if you prefer to work with each event having its own method. This might be useful when you always want to process each type of event in a different way.

Example:

Watcher that calculates how much time passed between the begin and commit of a WAL transaction.

“‘ruby class MeasureTransactionTimeWatcher

include Wal::Watcher
include Wal::Watcher::SeparatedEvents

def on_begin(event)
  @start_time = Time.current
end

def on_commit(event)
  puts "Transaction processing time: #{Time.current - @start_time}"
end

end “‘

Instance Method Summary collapse

Instance Method Details

#on_begin(event) ⇒ Object



63
# File 'lib/wal/watcher.rb', line 63

def on_begin(event); end

#on_commit(event) ⇒ Object



67
# File 'lib/wal/watcher.rb', line 67

def on_commit(event); end

#on_delete(event) ⇒ Object



66
# File 'lib/wal/watcher.rb', line 66

def on_delete(event); end

#on_event(event) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wal/watcher.rb', line 48

def on_event(event)
  case event
  when BeginTransactionEvent
    on_begin(event)
  when CommitTransactionEvent
    on_commit(event)
  when InsertEvent
    on_insert(event)
  when UpdateEvent
    on_update(event)
  when DeleteEvent
    on_delete(event)
  end
end

#on_insert(event) ⇒ Object



64
# File 'lib/wal/watcher.rb', line 64

def on_insert(event); end

#on_update(event) ⇒ Object



65
# File 'lib/wal/watcher.rb', line 65

def on_update(event); end