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

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

Instance Method Summary collapse

Constructor Details

#initialize(strategy) ⇒ Subscriber

Returns a new instance of Subscriber.



13
14
15
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 13

def initialize(strategy)
  @strategy = strategy
end

Instance Method Details

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



17
18
19
20
21
22
23
24
25
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 17

def call(_, _, _, _, payload)
  sql = payload[:sql]
  match = sql.match(/\A\s*INSERT(?:\s+IGNORE)?(?:\s+INTO)?\s+(?:\.*[`"]?([^.\s`"]+)[`"]?)*/i)
  return unless match
  table = match[1]
  if table
    @strategy.tables << table
  end
end