Class: IO::Endpoint::CompositeEndpoint
- Defined in:
- lib/io/endpoint/composite_endpoint.rb
Overview
A composite endpoint is a collection of endpoints that are used in order.
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
- #The endpoints in this composite endpoint.(endpoints) ⇒ Object readonly
Attributes inherited from Generic
Instance Method Summary collapse
-
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind all endpoints in the composite.
-
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connect to the first endpoint that succeeds.
-
#each(&block) ⇒ Object
Enumerate all endpoints in the composite endpoint.
-
#initialize(endpoints, **options) ⇒ CompositeEndpoint
constructor
Initialize a new composite endpoint.
-
#inspect ⇒ Object
Get a detailed string representation of the composite endpoint.
-
#size ⇒ Object
The number of endpoints in the composite endpoint.
-
#to_s ⇒ Object
Get a string representation of the composite endpoint.
-
#with(**options) ⇒ Object
Create a new composite endpoint with merged options.
Methods inherited from Generic
#accept, #bound, #connected, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #wrapper
Constructor Details
#initialize(endpoints, **options) ⇒ CompositeEndpoint
Initialize a new composite endpoint.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 14 def initialize(endpoints, **) super(**) # If any options were provided, propagate them to the endpoints: if .any? endpoints = endpoints.map{|endpoint| endpoint.with(**)} end @endpoints = endpoints end |
Instance Attribute Details
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
45 46 47 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 45 def endpoints @endpoints end |
#The endpoints in this composite endpoint.(endpoints) ⇒ Object (readonly)
45 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 45 attr :endpoints |
Instance Method Details
#bind(wrapper = self.wrapper, &block) ⇒ Object
Bind all endpoints in the composite.
85 86 87 88 89 90 91 92 93 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 85 def bind(wrapper = self.wrapper, &block) if block_given? @endpoints.each do |endpoint| endpoint.bind(&block) end else @endpoints.map(&:bind).flatten.compact end end |
#connect(wrapper = self.wrapper, &block) ⇒ Object
Connect to the first endpoint that succeeds.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 67 def connect(wrapper = self.wrapper, &block) last_error = nil @endpoints.each do |endpoint| begin return endpoint.connect(wrapper, &block) rescue => last_error end end raise last_error end |
#each(&block) ⇒ Object
Enumerate all endpoints in the composite endpoint.
55 56 57 58 59 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 55 def each(&block) @endpoints.each do |endpoint| endpoint.each(&block) end end |
#inspect ⇒ Object
Get a detailed string representation of the composite endpoint.
33 34 35 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 33 def inspect "\#<#{self.class} endpoints=#{@endpoints}>" end |
#size ⇒ Object
The number of endpoints in the composite endpoint.
48 49 50 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 48 def size @endpoints.size end |
#to_s ⇒ Object
Get a string representation of the composite endpoint.
27 28 29 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 27 def to_s "composite:#{@endpoints.join(",")}" end |
#with(**options) ⇒ Object
Create a new composite endpoint with merged options.
40 41 42 |
# File 'lib/io/endpoint/composite_endpoint.rb', line 40 def with(**) self.class.new(endpoints.map{|endpoint| endpoint.with(**)}, **@options.merge()) end |