Class: IO::Endpoint::CompositeEndpoint
- Inherits:
-
Generic
- Object
- Generic
- IO::Endpoint::CompositeEndpoint
show all
- 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
Attributes inherited from Generic
#options
Instance Method Summary
collapse
Methods inherited from Generic
#accept, #bound, #connected, #hostname, #linger, #local_address, parse, #reuse_address?, #reuse_port?, #timeout, #wrapper
Constructor Details
#initialize(endpoints, **options) ⇒ CompositeEndpoint
Returns a new instance of CompositeEndpoint.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 11
def initialize(endpoints, **options)
super(**options)
if options.any?
endpoints = endpoints.map{|endpoint| endpoint.with(**options)}
end
@endpoints = endpoints
end
|
Instance Attribute Details
#endpoints ⇒ Object
Returns the value of attribute endpoints.
34
35
36
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 34
def endpoints
@endpoints
end
|
Instance Method Details
#bind(wrapper = self.wrapper, &block) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 60
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
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 47
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
41
42
43
44
45
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 41
def each(&block)
@endpoints.each do |endpoint|
endpoint.each(&block)
end
end
|
#inspect ⇒ Object
26
27
28
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 26
def inspect
"\#<#{self.class} endpoints=#{@endpoints}>"
end
|
#size ⇒ Object
The number of endpoints in the composite endpoint.
37
38
39
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 37
def size
@endpoints.size
end
|
#to_s ⇒ Object
22
23
24
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 22
def to_s
"composite:#{@endpoints.join(",")}"
end
|
#with(**options) ⇒ Object
30
31
32
|
# File 'lib/io/endpoint/composite_endpoint.rb', line 30
def with(**options)
self.class.new(endpoints.map{|endpoint| endpoint.with(**options)}, **@options.merge(options))
end
|