Exception: StubRequests::EndpointNotFound

Inherits:
Error
  • Object
show all
Defined in:
lib/stub_requests/exceptions.rb

Overview

EndpointNotFound is raised when an endpoint cannot be found

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, suggestions: []) ⇒ EndpointNotFound

Returns a new instance of EndpointNotFound

Since:

  • 0.1.0



21
22
23
24
25
26
# File 'lib/stub_requests/exceptions.rb', line 21

def initialize(id:, suggestions: [])
  @id           = id
  @suggestions  = Array(suggestions).compact
  error_message = [base_message, suggestions_message].join(".")
  super(error_message)
end

Instance Attribute Details

#idObject (readonly)

Since:

  • 0.1.0



19
20
21
# File 'lib/stub_requests/exceptions.rb', line 19

def id
  @id
end

Instance Method Details

#base_messageObject

Since:

  • 0.1.0



28
29
30
# File 'lib/stub_requests/exceptions.rb', line 28

def base_message
  @base_message ||= "Couldn't find an endpoint with id=:#{id}"
end

#suggestionsObject

Since:

  • 0.1.0



38
39
40
# File 'lib/stub_requests/exceptions.rb', line 38

def suggestions
  @suggestions.map { |sym| ":#{sym}" }
end

#suggestions_messageObject

Since:

  • 0.1.0



32
33
34
35
36
# File 'lib/stub_requests/exceptions.rb', line 32

def suggestions_message
  return if suggestions.none?

  @suggestions_message ||= " Did you mean one of the following? (#{suggestions_string})"
end

#suggestions_stringObject

Since:

  • 0.1.0



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

def suggestions_string
  suggestions.join(", ")
end