Class: MockRedis::PipelinedWrapper
- Inherits:
-
Object
- Object
- MockRedis::PipelinedWrapper
show all
- Includes:
- UndefRedisMethods
- Defined in:
- lib/mock_redis/pipelined_wrapper.rb
Instance Method Summary
collapse
included
Constructor Details
Returns a new instance of PipelinedWrapper.
30
31
32
33
34
|
# File 'lib/mock_redis/pipelined_wrapper.rb', line 30
def initialize(db)
@db = db
@pipelined_futures = []
@in_pipeline = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/mock_redis/pipelined_wrapper.rb', line 42
def method_missing(method, *args, &block)
if @in_pipeline
future = MockRedis::Future.new([method, *args])
@pipelined_futures << future
future
else
@db.send(method, *args, &block)
end
end
|
Instance Method Details
#initialize_copy(source) ⇒ Object
36
37
38
39
40
|
# File 'lib/mock_redis/pipelined_wrapper.rb', line 36
def initialize_copy(source)
super
@db = @db.clone
@pipelined_futures = @pipelined_futures.clone
end
|
#pipelined(options = {}) {|_self| ... } ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/mock_redis/pipelined_wrapper.rb', line 52
def pipelined(options = {})
@in_pipeline = true
yield self
@in_pipeline = false
responses = @pipelined_futures.map do |future|
begin
result = send(*future.command)
future.set_result(result)
result
rescue => e
e
end
end
@pipelined_futures = []
responses
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
26
27
28
|
# File 'lib/mock_redis/pipelined_wrapper.rb', line 26
def respond_to?(method, include_private=false)
super || @db.respond_to?(method)
end
|