Class: StubRequests::Service
- Includes:
- Comparable, Concerns::Property, Concerns::RegisterVerb
- Defined in:
- lib/stub_requests/service.rb
Overview
Class Service provides details for a registered service
Instance Attribute Summary collapse
-
#id ⇒ Symbol
The id of the service.
-
#uri ⇒ String
The base uri to the service.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#endpoints ⇒ Array<Endpoints>
The endpoints for this service.
-
#endpoints? ⇒ true, false
Check if the endpoint registry has endpoints.
-
#endpoints_string ⇒ String
Returns a nicely formatted string with an array of endpoints.
- #hash ⇒ Object
-
#initialize(service_id, service_uri) ⇒ Service
constructor
Initializes a new instance of a Service.
-
#register(endpoint_id, verb, path) ⇒ Endpoint
Register and endpoint for this service.
-
#to_s ⇒ String
Returns a nicely formatted string with this service.
Methods included from Concerns::RegisterVerb
#any, #delete, #get, #patch, #post, #put
Methods included from Concerns::Property
Methods included from Concerns::ArgumentValidation
Constructor Details
#initialize(service_id, service_uri) ⇒ Service
Initializes a new instance of a Service
40 41 42 43 |
# File 'lib/stub_requests/service.rb', line 40 def initialize(service_id, service_uri) self.id = service_id self.uri = service_uri end |
Instance Attribute Details
Instance Method Details
#<=>(other) ⇒ Object
99 100 101 |
# File 'lib/stub_requests/service.rb', line 99 def <=>(other) id <=> other.id end |
#endpoints ⇒ Array<Endpoints>
The endpoints for this service
80 81 82 |
# File 'lib/stub_requests/service.rb', line 80 def endpoints EndpointRegistry[id] end |
#endpoints? ⇒ true, false
Check if the endpoint registry has endpoints
70 71 72 |
# File 'lib/stub_requests/service.rb', line 70 def endpoints? endpoints.any? end |
#endpoints_string ⇒ String
Returns a nicely formatted string with an array of endpoints
115 116 117 |
# File 'lib/stub_requests/service.rb', line 115 def endpoints_string "[#{endpoints_as_string}]" end |
#hash ⇒ Object
103 104 105 |
# File 'lib/stub_requests/service.rb', line 103 def hash [id, self.class].hash end |
#register(endpoint_id, verb, path) ⇒ Endpoint
Register and endpoint for this service
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stub_requests/service.rb', line 54 def register(endpoint_id, verb, path) endpoint = Endpoint.new( service_id: id, service_uri: uri, endpoint_id: endpoint_id, verb: verb, path: path, ) EndpointRegistry.instance.register(endpoint) end |
#to_s ⇒ String
Returns a nicely formatted string with this service
89 90 91 92 93 94 95 96 97 |
# File 'lib/stub_requests/service.rb', line 89 def to_s [ +"#<#{self.class}", +" id=#{id}", +" uri=#{uri}", +" endpoints=#{endpoints_string}", +">", ].join("") end |