class DatabaseFlusher::Cleaner

Attributes

strategy[R]

Public Class Methods

new(orm) click to toggle source
# File lib/database_flusher/cleaner.rb, line 6
def initialize(orm)
  @orm = orm
  reset_strategy
end

Public Instance Methods

clean() click to toggle source
# File lib/database_flusher/cleaner.rb, line 36
def clean
  strategy.clean
end
clean_with(name) click to toggle source
# File lib/database_flusher/cleaner.rb, line 23
def clean_with(name)
  self.strategy = name
  strategy.clean_all
end
start() click to toggle source
# File lib/database_flusher/cleaner.rb, line 28
def start
  strategy.start
end
stop() click to toggle source
# File lib/database_flusher/cleaner.rb, line 32
def stop
  strategy.stop
end
strategy=(name) click to toggle source
# File lib/database_flusher/cleaner.rb, line 11
def strategy=(name)
  strategy_changed = name != @strategy_name

  stop if strategy_changed

  if name
    create_strategy(name) if strategy_changed
  else
    reset_strategy
  end
end

Private Instance Methods

classify(name) click to toggle source
# File lib/database_flusher/cleaner.rb, line 54
def classify(name)
  name.to_s.split('_').collect(&:capitalize).join
end
create_strategy(name) click to toggle source
# File lib/database_flusher/cleaner.rb, line 42
def create_strategy(name)
  @strategy_name = name
  @strategy = DatabaseFlusher.
    const_get(classify(@orm)).
    const_get("#{classify(name)}Strategy").new
end
reset_strategy() click to toggle source
# File lib/database_flusher/cleaner.rb, line 49
def reset_strategy
  @strategy_name = nil
  @strategy = DatabaseFlusher::NullStrategy.new
end