Class: MockRedis

Inherits:
Object
  • Object
show all
Includes:
UndefRedisMethods
Defined in:
lib/mock_redis/version.rb,
lib/mock_redis.rb,
lib/mock_redis/zset.rb,
lib/mock_redis/future.rb,
lib/mock_redis/database.rb,
lib/mock_redis/assertions.rb,
lib/mock_redis/exceptions.rb,
lib/mock_redis/info_method.rb,
lib/mock_redis/set_methods.rb,
lib/mock_redis/sort_method.rb,
lib/mock_redis/hash_methods.rb,
lib/mock_redis/list_methods.rb,
lib/mock_redis/zset_methods.rb,
lib/mock_redis/expire_wrapper.rb,
lib/mock_redis/string_methods.rb,
lib/mock_redis/utility_methods.rb,
lib/mock_redis/indifferent_hash.rb,
lib/mock_redis/multi_db_wrapper.rb,
lib/mock_redis/pipelined_wrapper.rb,
lib/mock_redis/transaction_wrapper.rb,
lib/mock_redis/undef_redis_methods.rb

Overview

Defines the gem version.

Defined Under Namespace

Modules: Assertions, HashMethods, InfoMethod, ListMethods, SetMethods, SortMethod, StringMethods, UndefRedisMethods, UtilityMethods, ZsetMethods Classes: Database, ExpireWrapper, Future, FutureNotReady, IndifferentHash, MultiDbWrapper, PipelinedWrapper, TransactionWrapper, Zset

Constant Summary collapse

DEFAULTS =
{
   :scheme => "redis",
   :host => "127.0.0.1",
   :port => 6379,
   :path => nil,
   :timeout => 5.0,
   :password => nil,
   :db => 0,
   :time_class => Time,
}
VERSION =
'0.14.0'
WouldBlock =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UndefRedisMethods

included

Constructor Details

#initialize(*args) ⇒ MockRedis

Returns a new instance of MockRedis.



32
33
34
35
36
37
38
39
40
# File 'lib/mock_redis.rb', line 32

def initialize(*args)
  @options = _parse_options(args.first)

  @db = PipelinedWrapper.new(
    TransactionWrapper.new(
      ExpireWrapper.new(
        MultiDbWrapper.new(
            Database.new(self, *args)))))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



87
88
89
# File 'lib/mock_redis.rb', line 87

def method_missing(method, *args, &block)
  @db.send(method, *args, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/mock_redis.rb', line 15

def options
  @options
end

Class Method Details

.connect(*args) ⇒ Object



28
29
30
# File 'lib/mock_redis.rb', line 28

def self.connect(*args)
  new(*args)
end

Instance Method Details

#call(command, &block) ⇒ Object



47
48
49
# File 'lib/mock_redis.rb', line 47

def call(command, &block)
   self.send(*command)
end

#clientObject



71
72
73
# File 'lib/mock_redis.rb', line 71

def client
  self
end

#connectObject



75
76
77
# File 'lib/mock_redis.rb', line 75

def connect
  self
end

#dbObject



59
60
61
# File 'lib/mock_redis.rb', line 59

def db
  self.options[:db]
end

#hostObject



51
52
53
# File 'lib/mock_redis.rb', line 51

def host
  self.options[:host]
end

#idObject Also known as: location



42
43
44
# File 'lib/mock_redis.rb', line 42

def id
  "redis://#{self.host}:#{self.port}/#{self.db}"
end

#initialize_copy(source) ⇒ Object



91
92
93
94
# File 'lib/mock_redis.rb', line 91

def initialize_copy(source)
  super
  @db = @db.clone
end

#nowObject



63
64
65
# File 'lib/mock_redis.rb', line 63

def now
  self.options[:time_class].now
end

#portObject



55
56
57
# File 'lib/mock_redis.rb', line 55

def port
  self.options[:port]
end

#reconnectObject



79
80
81
# File 'lib/mock_redis.rb', line 79

def reconnect
  self
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/mock_redis.rb', line 83

def respond_to?(method, include_private=false)
  super || @db.respond_to?(method, include_private)
end

#time_at(timestamp) ⇒ Object



67
68
69
# File 'lib/mock_redis.rb', line 67

def time_at(timestamp)
  self.options[:time_class].at(timestamp)
end