@@ -160,7 +160,7 @@ def self.multi(nodes, opts={})
160
160
161
161
# Initialize a connection to MongoDB using the MongoDB URI spec.
162
162
#
163
- # Since MongoClient.new cannot be used with any <code>ENV["MONGODB_URI"]</code> that has multiple hosts (implying a replicaset),
163
+ # Since MongoClient.new cannot be used with any <code>ENV["MONGODB_URI"]</code> that has multiple hosts (implying a replicaset),
164
164
# you may use this when the type of your connection varies by environment and should be determined solely from <code>ENV["MONGODB_URI"]</code>.
165
165
#
166
166
# @param uri [String]
@@ -469,7 +469,7 @@ def connect
469
469
# NOTE: Do check if this needs to be more stringent.
470
470
# Probably not since if any node raises a connection failure, all nodes will be closed.
471
471
def connected?
472
- @primary_pool && !@primary_pool . closed?
472
+ !! ( @primary_pool && !@primary_pool . closed? )
473
473
end
474
474
475
475
# Determine if the connection is active. In a normal case the *server_info* operation
@@ -545,6 +545,32 @@ def checkin(socket)
545
545
end
546
546
end
547
547
548
+ # Internal method for checking isMaster() on a given node.
549
+ #
550
+ # @param node [Array] Port and host for the target node
551
+ # @return [Hash] Response from isMaster()
552
+ #
553
+ # @private
554
+ def check_is_master ( node )
555
+ begin
556
+ host , port = *node
557
+ config = nil
558
+ socket = @socket_class . new ( host , port , @op_timeout , @connect_timeout )
559
+ if @connect_timeout
560
+ Timeout ::timeout ( @connect_timeout , OperationTimeout ) do
561
+ config = self [ 'admin' ] . command ( { :ismaster => 1 } , :socket => socket )
562
+ end
563
+ else
564
+ config = self [ 'admin' ] . command ( { :ismaster => 1 } , :socket => socket )
565
+ end
566
+ rescue OperationFailure , SocketError , SystemCallError , IOError
567
+ close
568
+ ensure
569
+ socket . close unless socket . nil? || socket . closed?
570
+ end
571
+ config
572
+ end
573
+
548
574
protected
549
575
550
576
def valid_opts
@@ -621,31 +647,6 @@ def setup(opts)
621
647
622
648
private
623
649
624
- def check_is_master ( node )
625
- begin
626
- host , port = *node
627
- socket = nil
628
- config = nil
629
-
630
- socket = @socket_class . new ( host , port , @op_timeout , @connect_timeout )
631
- if ( @connect_timeout )
632
- Timeout ::timeout ( @connect_timeout , OperationTimeout ) do
633
- config = self [ 'admin' ] . command ( { :ismaster => 1 } , :socket => socket )
634
- end
635
- else
636
- config = self [ 'admin' ] . command ( { :ismaster => 1 } , :socket => socket )
637
- end
638
- rescue OperationFailure , SocketError , SystemCallError , IOError
639
- close
640
- ensure
641
- if socket
642
- socket . close unless socket . closed?
643
- end
644
- end
645
-
646
- config
647
- end
648
-
649
650
# Set the specified node as primary.
650
651
def set_primary ( node )
651
652
host , port = *node
0 commit comments