Module: Rackr::Router::Errors

Defined in:
lib/rackr/router/errors.rb

Overview

Errors for the router

Defined Under Namespace

Classes: Error, InvalidBranchNameError, InvalidCallbackError, InvalidEndpointError, InvalidNamedRouteError, InvalidPathError, InvalidRackResponseError, UndefinedNamedRouteError

Class Method Summary collapse

Class Method Details

.check_as(as, path) ⇒ Object



41
42
43
44
45
46
# File 'lib/rackr/router/errors.rb', line 41

def check_as(as, path)
  return if as.is_a?(String) || as.is_a?(Symbol) || as.nil?

  raise(InvalidNamedRouteError,
        "as: argument in routes and scopes must be a `string` or a `symbol`, got: '#{as}' for '#{path}'")
end

.check_callbacks(callbacks, path) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/rackr/router/errors.rb', line 48

def check_callbacks(callbacks, path)
  check = lambda { |callback|
    unless callback.nil? || callback.respond_to?(:call) || (callback.respond_to?(:new) && callback.method_defined?(:call))
      raise(InvalidCallbackError,
            "Callbacks must respond to a `call` method or be a class with a `call` instance method, got: '#{callback.inspect}' for '#{path}'")
    end
  }

  callbacks.is_a?(Array) ? callbacks.compact.each(&check) : check.call(callbacks)
end

.check_endpoint(endpoint, path) ⇒ Object



59
60
61
62
63
64
# File 'lib/rackr/router/errors.rb', line 59

def check_endpoint(endpoint, path)
  return if endpoint.respond_to?(:call) || (endpoint.respond_to?(:new) && endpoint.method_defined?(:call))

  raise(InvalidEndpointError,
        "Endpoints must respond to a `call` method or be a class with a `call` instance method, got: '#{endpoint.inspect}' for '#{path}'")
end

.check_path(path) ⇒ Object

Raises:



35
36
37
38
39
# File 'lib/rackr/router/errors.rb', line 35

def check_path(path)
  return if path.is_a?(String) || path.is_a?(Symbol) || path.nil?

  raise(InvalidPathError, "Path must be a `string`, `symbol` or `nil`, got: '#{path}'")
end

.check_rack_response(response, where) ⇒ Object



17
18
19
20
21
# File 'lib/rackr/router/errors.rb', line 17

def check_rack_response(response, where)
  return if response.is_a?(Array)

  raise(InvalidRackResponseError, "Invalid Rack response in #{where}, received: #{response}")
end

.check_scope_name(path) ⇒ Object



23
24
25
26
27
# File 'lib/rackr/router/errors.rb', line 23

def check_scope_name(path)
  return if path.is_a?(String) || path.is_a?(Symbol) || path.nil?

  raise(InvalidBranchNameError, "Route scope name must be a `string` or a `symbol`, got: '#{path}'")
end

.check_scope_slashes(path) ⇒ Object



29
30
31
32
33
# File 'lib/rackr/router/errors.rb', line 29

def check_scope_slashes(path)
  return unless path.is_a?(String) && path.include?('/')

  raise(InvalidBranchNameError, "Avoid slashes in scope name, use nested scopes instead, got: '#{path}'")
end