Class: DatabaseFlusher::ActiveRecord::DeletionStrategy
- Inherits:
-
Object
- Object
- DatabaseFlusher::ActiveRecord::DeletionStrategy
- Defined in:
- lib/database_flusher/active_record/deletion_strategy.rb
Defined Under Namespace
Classes: Subscriber
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize ⇒ DeletionStrategy
constructor
A new instance of DeletionStrategy.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ DeletionStrategy
Returns a new instance of DeletionStrategy.
28 29 30 |
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 28 def initialize @tables = Set.new end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 10 def adapter @adapter end |
#tables ⇒ Object (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
#clean ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 50 def clean return if tables.empty? # puts "Cleaning #{tables.inspect}" adapter.delete(*tables) tables.clear end |
#start ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 32 def start @subscriber ||= ActiveSupport::Notifications.subscribe( 'sql.active_record', Subscriber.new(self) ) connection = ::ActiveRecord::Base.connection @adapter = DatabaseFlusher::ActiveRecord. const_get("#{connection.adapter_name}Adapter"). new(connection) end |
#stop ⇒ Object
43 44 45 46 47 48 |
# File 'lib/database_flusher/active_record/deletion_strategy.rb', line 43 def stop if @subscriber ActiveSupport::Notifications.unsubscribe(@subscriber) @subscriber = nil end end |