Class: Ecco::SaveEventListener

Inherits:
EventListener show all
Defined in:
lib/ecco/save_event_listener.rb

Constant Summary collapse

SAVE_EVENTS =
{
  EventType::QUERY           => "QUERY",
  EventType::ROTATE          => "ROTATE",
  EventType::WRITE_ROWS      => "WRITE_ROWS",
  EventType::EXT_WRITE_ROWS  => "WRITE_ROWS",
  EventType::UPDATE_ROWS     => "UPDATE_ROWS",
  EventType::EXT_UPDATE_ROWS => "UPDATE_ROWS",
  EventType::DELETE_ROWS     => "DELETE_ROWS",
  EventType::EXT_DELETE_ROWS => "DELETE_ROWS",
}

Instance Attribute Summary

Attributes inherited from EventListener

#callback

Instance Method Summary collapse

Methods inherited from EventListener

#initialize

Constructor Details

This class inherits a constructor from Ecco::EventListener

Instance Method Details

#accepted_eventsObject



16
17
18
# File 'lib/ecco/save_event_listener.rb', line 16

def accepted_events
  SAVE_EVENTS.keys
end

#on_event(event) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ecco/save_event_listener.rb', line 20

def on_event(event)
  type = event.get_header.get_event_type

  case type
  when *accepted_events
    filename        = @client.get_binlog_filename
    position        = @client.get_binlog_position
    event_type_name = SAVE_EVENTS.fetch(type)

    @callback.call(filename, position, event_type_name)
  end
end