class MockRedis::PipelinedWrapper

Public Class Methods

new(db) click to toggle source
# File lib/mock_redis/pipelined_wrapper.rb, line 9
def initialize(db)
  @db = db
  @pipelined_futures = []
  @nesting_level = 0
end

Public Instance Methods

initialize_copy(source) click to toggle source
Calls superclass method
# File lib/mock_redis/pipelined_wrapper.rb, line 15
def initialize_copy(source)
  super
  @db = @db.clone
  @pipelined_futures = @pipelined_futures.clone
end
method_missing(method, *args, &block) click to toggle source
# File lib/mock_redis/pipelined_wrapper.rb, line 21
               def method_missing(method, *args, &block)
  if in_pipeline?
    future = MockRedis::Future.new([method, *args], block)
    @pipelined_futures << future
    future
  else
    @db.send(method, *args, &block)
  end
end
pipelined(_options = {}) { |self| ... } click to toggle source
# File lib/mock_redis/pipelined_wrapper.rb, line 31
def pipelined(_options = {})
  begin
    @nesting_level += 1
    yield self
  ensure
    @nesting_level -= 1
  end

  if in_pipeline?
    return
  end

  responses = @pipelined_futures.flat_map do |future|
    begin
      result = if future.block
                 send(*future.command, &future.block)
               else
                 send(*future.command)
               end
      future.store_result(result)

      if future.block
        result
      else
        [result]
      end
    rescue StandardError => e
      e
    end
  end
  @pipelined_futures = []
  responses
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/mock_redis/pipelined_wrapper.rb, line 5
def respond_to?(method, include_private = false)
  super || @db.respond_to?(method)
end

Private Instance Methods

in_pipeline?() click to toggle source
# File lib/mock_redis/pipelined_wrapper.rb, line 67
def in_pipeline?
  @nesting_level > 0
end