class StubRequests::Service
Class
Service
provides details for a registered service
@author Mikael Henriksson <mikael@zoolutions.se>
Public Class Methods
new(service_id, service_uri)
click to toggle source
Initializes a new instance of a Service
@param [Symbol] service_id the id of this service @param [String] service_uri the base uri to reach the service
# File lib/stub_requests/service.rb, line 40 def initialize(service_id, service_uri) self.id = service_id self.uri = service_uri end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/stub_requests/service.rb, line 99 def <=>(other) id <=> other.id end
endpoints()
click to toggle source
The endpoints for this service
@return [Array<Endpoints>]
# File lib/stub_requests/service.rb, line 80 def endpoints EndpointRegistry[id] end
endpoints?()
click to toggle source
Check if the endpoint registry has endpoints
@return [true,false]
# File lib/stub_requests/service.rb, line 70 def endpoints? endpoints.any? end
endpoints_string()
click to toggle source
Returns a nicely formatted string with an array of endpoints
@return [String]
# File lib/stub_requests/service.rb, line 115 def endpoints_string "[#{endpoints_as_string}]" end
hash()
click to toggle source
# File lib/stub_requests/service.rb, line 103 def hash [id, self.class].hash end
register(endpoint_id, verb, path)
click to toggle source
Register and endpoint for this service
@param [Symbol] endpoint_id the id of the endpoint @param [Symbol] verb the HTTP verb/method @param [String] path the path to the endpoint
@return [Endpoint] the endpoint that was registered
# 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()
click to toggle source
Returns a nicely formatted string with this service
@return [String]
# File lib/stub_requests/service.rb, line 89 def to_s [ +"#<#{self.class}", +" id=#{id}", +" uri=#{uri}", +" endpoints=#{endpoints_string}", +">", ].join("") end
Private Instance Methods
endpoints_as_string()
click to toggle source
# File lib/stub_requests/service.rb, line 121 def endpoints_as_string endpoints.map(&:to_s).join(",") if endpoints? end