Class: Net::TCPClient::Policy::Base
- Inherits:
-
Object
- Object
- Net::TCPClient::Policy::Base
- Defined in:
- lib/net/tcp_client/policy/base.rb
Overview
Policy for connecting to servers in the order specified
Instance Attribute Summary collapse
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
Class Method Summary collapse
-
.factory(policy, server_names) ⇒ Object
Returns a policy instance for the supplied policy type.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Calls the block once for each server, with the addresses in order.
-
#initialize(server_names) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(server_names) ⇒ Base
Returns a new instance of Base.
23 24 25 26 |
# File 'lib/net/tcp_client/policy/base.rb', line 23 def initialize(server_names) # Collect Addresses for the supplied server_names @addresses = Array(server_names).collect { |name| Address.addresses_for_server_name(name) }.flatten end |
Instance Attribute Details
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
6 7 8 |
# File 'lib/net/tcp_client/policy/base.rb', line 6 def addresses @addresses end |
Class Method Details
.factory(policy, server_names) ⇒ Object
Returns a policy instance for the supplied policy type
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/net/tcp_client/policy/base.rb', line 9 def self.factory(policy, server_names) case policy when :ordered # Policy for connecting to servers in the order specified Ordered.new(server_names) when :random Random.new(server_names) when Proc Custom.new(server_names, policy) else raise(ArgumentError, "Invalid policy: #{policy.inspect}") end end |
Instance Method Details
#each(&block) ⇒ Object
Calls the block once for each server, with the addresses in order
29 30 31 |
# File 'lib/net/tcp_client/policy/base.rb', line 29 def each(&block) raise NotImplementedError end |