Class: DatabaseFlusher::ActiveRecord::DeletionStrategy

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

Defined Under Namespace

Classes: Subscriber

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeletionStrategy



28
29
30
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 28

def initialize
  @tables = Set.new
end

Instance Attribute Details

#tablesObject (readonly)

Returns the value of attribute tables.



10
11
12
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 10

def tables
  @tables
end

Instance Method Details

#cleanObject



46
47
48
49
50
51
52
53
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 46

def clean
  return if tables.empty?

  # puts "Cleaning #{tables.inspect}"
  adapter.delete(*tables)

  tables.clear
end

#clean_allObject



55
56
57
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 55

def clean_all
  adapter.delete(*all_tables)
end

#startObject



32
33
34
35
36
37
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 32

def start
  @subscriber ||= ActiveSupport::Notifications.subscribe(
    'sql.active_record',
    Subscriber.new(self)
  )
end

#stopObject



39
40
41
42
43
44
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 39

def stop
  if @subscriber
    ActiveSupport::Notifications.unsubscribe(@subscriber)
    @subscriber = nil
  end
end