Class: StubRequests::Endpoint

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

Overview

Class Endpoint provides registration of stubbed endpoints

Author:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Property

included

Methods included from Concerns::ArgumentValidation

#validate!, #validate_type!

Constructor Details

#initialize(endpoint_id:, service_id:, service_uri:, verb:, path:) ⇒ Endpoint

Initialize an endpoint for a specific Service

Parameters:

  • endpoint_id (Symbol)

    a descriptive id for the endpoint

  • service_id (Symbol)

    the id of a registered service

  • service_uri (String)

    the uri of a registered service

  • verb (Symbol)

    a HTTP verb

  • path (String)

    how to reach the endpoint

Since:

  • 0.1.0



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/stub_requests/endpoint.rb', line 64

def initialize(endpoint_id:, service_id:, service_uri:, verb:, path:)
  self.id       = endpoint_id
  self.verb     = verb
  self.path     = path

  @service_id   = service_id
  @service_uri  = service_uri
  @uri          = URI.safe_join(service_uri, path)
  @route_params = URI.route_params(path)
  @stubs        = Concurrent::Array.new
end

Instance Attribute Details

#idSymbol

Returns the id of the endpoint

Returns:

  • (Symbol)

    the id of the endpoint



25
# File 'lib/stub_requests/endpoint.rb', line 25

property :id, type: Symbol

#pathString

Returns a string template for the endpoint

Returns:

  • (String)

    a string template for the endpoint



33
# File 'lib/stub_requests/endpoint.rb', line 33

property :path, type: String

#route_paramsObject

Since:

  • 0.1.0



52
53
54
# File 'lib/stub_requests/endpoint.rb', line 52

def route_params
  @route_params
end

#service_idObject

Since:

  • 0.1.0



42
43
44
# File 'lib/stub_requests/endpoint.rb', line 42

def service_id
  @service_id
end

#service_uriObject

Since:

  • 0.1.0



47
48
49
# File 'lib/stub_requests/endpoint.rb', line 47

def service_uri
  @service_uri
end

#uriObject

Since:

  • 0.1.0



37
38
39
# File 'lib/stub_requests/endpoint.rb', line 37

def uri
  @uri
end

#verbSymbol

Returns a HTTP verb

Returns:



29
# File 'lib/stub_requests/endpoint.rb', line 29

property :verb, type: Symbol

Instance Method Details

#<=>(other) ⇒ Object

Since:

  • 0.1.0



91
92
93
94
# File 'lib/stub_requests/endpoint.rb', line 91

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

#hashObject

Since:

  • 0.1.0



96
97
98
# File 'lib/stub_requests/endpoint.rb', line 96

def hash
  [id, self.class].hash
end

#to_sString

Returns a descriptive string of this endpoint

Returns:

Since:

  • 0.1.0



107
108
109
# File 'lib/stub_requests/endpoint.rb', line 107

def to_s
  "#<#{self.class} id=:#{id} verb=:#{verb} path='#{path}'>"
end

#update(verb, path) ⇒ Endpoint

Updates this endpoint

Parameters:

  • verb (Symbol)

    a HTTP verb

  • path (String)

    how to reach the endpoint

Returns:

  • (Endpoint)

    returns the updated endpoint

Since:

  • 0.1.0



85
86
87
88
89
# File 'lib/stub_requests/endpoint.rb', line 85

def update(verb, path)
  @verb = verb
  @path = path
  self
end