Sha256: 9b2f5da3b8de607250aee9a8cd11020e6447539251733bc0a04bf88eee354613

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

require 'database_cleaner/generic/base'
require 'database_cleaner/deprecation'

module DatabaseCleaner
  module Redis
    def self.available_strategies
      %w{truncation deletion}
    end

    def self.default_strategy
      :truncation
    end

    module Base
      include ::DatabaseCleaner::Generic::Base

      def db=(desired_db)
        @db = desired_db
      end

      def db
        @db ||= :default
      end

      def url
        DatabaseCleaner.deprecate "The redis deletion strategy's #url method is deprecated. It will be removed in database_cleaner-redis 2.0 in favor of #db."
        db
      end

      private

      def connection
        @connection ||= begin
          if url == :default
            ::Redis.new
          elsif db.is_a?(::Redis) # pass directly the connection
            db
          else
            ::Redis.new(:url => db)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
database_cleaner-1.99.0 adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb
database_cleaner-redis-1.99.0 lib/database_cleaner/redis/base.rb
database_cleaner-1.99.0.beta adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb
database_cleaner-redis-1.99.0.beta lib/database_cleaner/redis/base.rb