Class: StubRequests::Service

Inherits:
Object
  • Object
show all
Includes:
Comparable, Concerns::Property, Concerns::RegisterVerb
Defined in:
lib/stub_requests/service.rb

Overview

Class Service provides details for a registered service

Author:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::RegisterVerb

#any, #delete, #get, #patch, #post, #put

Methods included from Concerns::Property

included

Methods included from Concerns::ArgumentValidation

#validate!, #validate_type!

Constructor Details

#initialize(service_id, service_uri) ⇒ Service

Initializes a new instance of a Service

Parameters:

  • service_id (Symbol)

    the id of this service

  • service_uri (String)

    the base uri to reach the service

Since:

  • 0.1.0



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

#idSymbol

Returns the id of the service

Returns:

  • (Symbol)

    the id of the service



28
# File 'lib/stub_requests/service.rb', line 28

property :id, type: Symbol

#uriString

Returns the base uri to the service

Returns:

  • (String)

    the base uri to the service



32
# File 'lib/stub_requests/service.rb', line 32

property :uri, type: String

Instance Method Details

#<=>(other) ⇒ Object

Since:

  • 0.1.0



99
100
101
# File 'lib/stub_requests/service.rb', line 99

def <=>(other)
  id <=> other.id
end

#endpointsArray<Endpoints>

The endpoints for this service

Returns:

Since:

  • 0.1.0



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

Returns:

  • (true, false)

Since:

  • 0.1.0



70
71
72
# File 'lib/stub_requests/service.rb', line 70

def endpoints?
  endpoints.any?
end

#endpoints_stringString

Returns a nicely formatted string with an array of endpoints

Returns:

Since:

  • 0.1.0



115
116
117
# File 'lib/stub_requests/service.rb', line 115

def endpoints_string
  "[#{endpoints_as_string}]"
end

#hashObject

Since:

  • 0.1.0



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

Parameters:

  • endpoint_id (Symbol)

    the id of the endpoint

  • verb (Symbol)

    the HTTP verb/method

  • path (String)

    the path to the endpoint

Returns:

  • (Endpoint)

    the endpoint that was registered

Since:

  • 0.1.0



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_sString

Returns a nicely formatted string with this service

Returns:

Since:

  • 0.1.0



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