Class: DatabaseFlusher::ActiveRecord::DeletionStrategy::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/database_flusher/active_record/deletion_strategy.rb

Constant Summary collapse

PATTERN =

INSERT [IGNORE] [INTO] schema_name.table_name

%r{
  \A\s*
  INSERT
  (?:\s+IGNORE)?
  (?:\s+INTO)?
  \s+
  (?:[`"]?([^.\s`"]+)[`"]?\.)? # schema
  (?:[`"]?([^.\s`"]+)[`"]?)    # table
}xi

Instance Method Summary collapse

Constructor Details

#initialize(strategy) ⇒ Subscriber

Returns a new instance of Subscriber.



24
25
26
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 24

def initialize(strategy)
  @strategy = strategy
end

Instance Method Details

#call(_, _, _, _, payload) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 28

def call(_, _, _, _, payload)
  sql = payload[:sql]
  match = sql.match(PATTERN)
  return unless match
  table  = match[2]
  if table
    schema = match[1]
    if schema
      table = "#{schema}.#{table}"
    end
    @strategy.tables << table
  end
end