Class: StubRequests::Service
- Includes:
- Comparable, ArgumentValidation
- Defined in:
- lib/stub_requests/service.rb
Overview
Class Service provides details for a registered service
Instance Attribute Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#endpoints? ⇒ true, false
Check if the endpoint registry has endpoints.
-
#get_endpoint(endpoint_id) ⇒ Endpoint?
Gets an endpoint from the #endpoint_registry collection.
-
#get_endpoint!(endpoint_id) ⇒ Endpoint
Gets an endpoint from the #endpoint_registry collection.
- #hash ⇒ Object
-
#initialize(service_id, service_uri) ⇒ Service
constructor
Initializes a new instance of a Service.
-
#register_endpoint(endpoint_id, verb, uri_template, default_options = {}) ⇒ Endpoint
Registers a new endpoint or updates an existing one.
-
#to_s ⇒ String
Returns a nicely formatted string with this service.
Methods included from ArgumentValidation
Constructor Details
#initialize(service_id, service_uri) ⇒ Service
Initializes a new instance of a Service
35 36 37 38 39 40 41 42 |
# File 'lib/stub_requests/service.rb', line 35 def initialize(service_id, service_uri) validate! service_id, is_a: Symbol validate! service_uri, is_a: String @id = service_id @uri = service_uri @endpoint_registry = EndpointRegistry.new end |
Instance Attribute Details
#endpoint_registry ⇒ Object
27 28 29 |
# File 'lib/stub_requests/service.rb', line 27 def endpoint_registry @endpoint_registry end |
Instance Method Details
#<=>(other) ⇒ Object
108 109 110 |
# File 'lib/stub_requests/service.rb', line 108 def <=>(other) id <=> other.id end |
#endpoints? ⇒ true, false
Check if the endpoint registry has endpoints
65 66 67 |
# File 'lib/stub_requests/service.rb', line 65 def endpoints? endpoint_registry.any? end |
#get_endpoint(endpoint_id) ⇒ Endpoint?
Gets an endpoint from the #endpoint_registry collection
89 90 91 |
# File 'lib/stub_requests/service.rb', line 89 def get_endpoint(endpoint_id) endpoint_registry.get(endpoint_id) end |
#get_endpoint!(endpoint_id) ⇒ Endpoint
Gets an endpoint from the #endpoint_registry collection
78 79 80 |
# File 'lib/stub_requests/service.rb', line 78 def get_endpoint!(endpoint_id) endpoint_registry.get!(endpoint_id) end |
#hash ⇒ Object
112 113 114 |
# File 'lib/stub_requests/service.rb', line 112 def hash [id, self.class].hash end |
#register_endpoint(endpoint_id, verb, uri_template, default_options = {}) ⇒ Endpoint
Registers a new endpoint or updates an existing one
:reek:LongParameterList { max_params: 5 }
56 57 58 |
# File 'lib/stub_requests/service.rb', line 56 def register_endpoint(endpoint_id, verb, uri_template, = {}) endpoint_registry.register(endpoint_id, verb, uri_template, ) end |
#to_s ⇒ String
Returns a nicely formatted string with this service
98 99 100 101 102 103 104 105 106 |
# File 'lib/stub_requests/service.rb', line 98 def to_s [ +"#<#{self.class}", +" id=#{id}", +" uri=#{uri}", +" endpoints=#{endpoint_registry.endpoints_string}", +">", ].join("") end |