Sha256: 12c6aeb212d6bd7880e4d95729208de3f18804985b5f779e80ac47993ce252b8

Contents?: true

Size: 871 Bytes

Versions: 5

Compression:

Stored size: 871 Bytes

Contents

# Abstract strategy class for orm adapter gems to subclass

module DatabaseCleaner
  class Strategy
    # Override this method if the strategy accepts options
    def initialize(options=nil)
      if options
        name = self.class.name.sub("DatabaseCleaner::","").sub("::"," ") # e.g. "ActiveRecord Transaction"
        raise ArgumentError, "No options are available for the #{name} strategy."
      end
    end

    def db
      @db ||= :default
    end
    attr_writer :db

    # Override this method to start a database transaction if the strategy uses them
    def start
    end

    # Override this method with the actual cleaning procedure. Its the only mandatory method implementation.
    def clean
      raise NotImplementedError
    end

    def cleaning(&block)
      begin
        start
        yield
      ensure
        clean
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb
database_cleaner-core-2.0.1 lib/database_cleaner/strategy.rb
database_cleaner-core-2.0.0 lib/database_cleaner/strategy.rb
database_cleaner-core-2.0.0.beta2 lib/database_cleaner/strategy.rb