Class: IO::Endpoint::NamedEndpoints
- Inherits:
-
Object
- Object
- IO::Endpoint::NamedEndpoints
- Defined in:
- lib/io/endpoint/named_endpoints.rb
Overview
A named endpoints collection is a hash of endpoints that can be accessed by name.
Unlike CompositeEndpoint, which treats endpoints as an ordered list for failover, NamedEndpoints allows you to access endpoints by symbolic names, making it useful for scenarios where you need to run the same application on multiple endpoints with different configurations (e.g., HTTP/1 and HTTP/2 on different ports).
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
- #The endpoints hash mapping names to endpoint instances.(endpointshashmappingnamestoendpointinstances.) ⇒ Object readonly
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access an endpoint by its name.
-
#bound(**options) ⇒ Object
Create a new named endpoints instance with all endpoints bound.
-
#close ⇒ Object
Close all endpoints in the collection.
-
#connected(**options) ⇒ Object
Create a new named endpoints instance with all endpoints connected.
-
#each(&block) ⇒ Object
Enumerate all endpoints with their names.
-
#initialize(endpoints) ⇒ NamedEndpoints
constructor
Initialize a new named endpoints collection.
-
#inspect ⇒ Object
Get a detailed string representation of the named endpoints.
-
#to_s ⇒ Object
Get a string representation of the named endpoints.
Constructor Details
#initialize(endpoints) ⇒ NamedEndpoints
Initialize a new named endpoints collection.
15 16 17 |
# File 'lib/io/endpoint/named_endpoints.rb', line 15 def initialize(endpoints) @endpoints = endpoints end |
Instance Attribute Details
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
38 39 40 |
# File 'lib/io/endpoint/named_endpoints.rb', line 38 def endpoints @endpoints end |
#The endpoints hash mapping names to endpoint instances.(endpointshashmappingnamestoendpointinstances.) ⇒ Object (readonly)
38 |
# File 'lib/io/endpoint/named_endpoints.rb', line 38 attr :endpoints |
Instance Method Details
#[](key) ⇒ Object
Access an endpoint by its name.
43 44 45 |
# File 'lib/io/endpoint/named_endpoints.rb', line 43 def [] key @endpoints[key] end |
#bound(**options) ⇒ Object
Create a new named endpoints instance with all endpoints bound.
58 59 60 61 62 |
# File 'lib/io/endpoint/named_endpoints.rb', line 58 def bound(**) self.class.new( @endpoints.transform_values{|endpoint| endpoint.bound(**)} ) end |
#close ⇒ Object
Close all endpoints in the collection.
Calls close on each endpoint value.
76 77 78 |
# File 'lib/io/endpoint/named_endpoints.rb', line 76 def close @endpoints.each_value(&:close) end |
#connected(**options) ⇒ Object
Create a new named endpoints instance with all endpoints connected.
67 68 69 70 71 |
# File 'lib/io/endpoint/named_endpoints.rb', line 67 def connected(**) self.class.new( @endpoints.transform_values{|endpoint| endpoint.connected(**)} ) end |
#each(&block) ⇒ Object
Enumerate all endpoints with their names.
51 52 53 |
# File 'lib/io/endpoint/named_endpoints.rb', line 51 def each(&block) @endpoints.each(&block) end |
#inspect ⇒ Object
Get a detailed string representation of the named endpoints.
30 31 32 33 34 35 |
# File 'lib/io/endpoint/named_endpoints.rb', line 30 def inspect parts = @endpoints.map do |name, endpoint| "#{name}: #{endpoint.inspect}" end "\#<#{self.class} #{parts.join(", ")}>" end |
#to_s ⇒ Object
Get a string representation of the named endpoints.
21 22 23 24 25 26 |
# File 'lib/io/endpoint/named_endpoints.rb', line 21 def to_s parts = @endpoints.map do |name, endpoint| "#{name}:#{endpoint}" end "named:#{parts.join(",")}" end |