Class: SimpleRedisOrm::ConnectionPoolProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-redis-orm/connection_pool_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool) ⇒ ConnectionPoolProxy

Returns a new instance of ConnectionPoolProxy.



3
4
5
6
7
# File 'lib/simple-redis-orm/connection_pool_proxy.rb', line 3

def initialize(pool)
  raise ArgumentError "Should only proxy ConnectionPool!" unless self.class.should_proxy?(pool)

  @pool = pool
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



9
10
11
# File 'lib/simple-redis-orm/connection_pool_proxy.rb', line 9

def method_missing(name, *args, &block)
  @pool.with { |x| x.send(name, *args, &block) }
end

Class Method Details

.proxy_if_needed(conn) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/simple-redis-orm/connection_pool_proxy.rb', line 23

def self.proxy_if_needed(conn)
  if should_proxy?(conn)
    ConnectionPoolProxy.new(conn)
  else
    conn
  end
end

.should_proxy?(conn) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/simple-redis-orm/connection_pool_proxy.rb', line 19

def self.should_proxy?(conn)
  defined?(::ConnectionPool) && conn.is_a?(::ConnectionPool)
end

Instance Method Details

#respond_to_missing?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/simple-redis-orm/connection_pool_proxy.rb', line 15

def respond_to_missing?(name, include_all = false)
  @pool.with { |x| x.respond_to?(name, include_all) }
end