Class: Monga::Connection
- Inherits:
-
Object
- Object
- Monga::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/monga/connection.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.proxy_connection_class(type, client) ⇒ Object
Returns name of proxy_connection class.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Connection
constructor
Simple connection wrapper.
Constructor Details
#initialize(opts) ⇒ Connection
Simple connection wrapper. Accpets
-
host/port or server
-
connection type
-
timeout
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/monga/connection.rb', line 14 def initialize(opts) @type = opts[:type] host, port = if server = opts[:server] h, p = server.split(":") [h, p.to_i] else h = opts[:host] || Monga::DEFAULT_HOST p = opts[:port] || Monga::DEFAULT_PORT [h, p] end timeout = opts[:timeout] @connection = case @type when :em require File.("../connections/em_connection", __FILE__) Monga::Connections::EMConnection.connect(host, port, timeout) when :sync require File.("../connections/em_connection", __FILE__) require File.("../connections/fibered_connection", __FILE__) Monga::Connections::FiberedConnection.connect(host, port, timeout) when :block require File.("../connections/kgio_connection", __FILE__) Monga::Connections::KGIOConnection.connect(host, port, timeout) else raise Monga::Exceptions::WrongConnectionType, "Connection type `#{opts[:type]}` is non valid, choose one of: :em, :sync, or :block" unless conn_type end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/monga/connection.rb', line 7 def type @type end |
Class Method Details
.proxy_connection_class(type, client) ⇒ Object
Returns name of proxy_connection class
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/monga/connection.rb', line 44 def self.proxy_connection_class(type, client) case type when :em require File.("../connections/em_proxy_connection", __FILE__) Monga::Connections::EMProxyConnection.new(client) when :sync require File.("../connections/em_proxy_connection", __FILE__) require File.("../connections/fibered_proxy_connection", __FILE__) Monga::Connections::FiberedProxyConnection.new(client) when :block require File.("../connections/proxy_connection", __FILE__) Monga::Connections::ProxyConnection.new(client) end end |