Module: Rackr::Router::Errors

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

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.check_as(as, path) ⇒ Object



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

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

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

.check_branch_name(path) ⇒ Object



15
16
17
18
19
# File 'lib/rackr/router/errors.rb', line 15

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

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

.check_callbacks(callbacks, path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/rackr/router/errors.rb', line 34

def check_callbacks(callbacks, path)
  check = lambda { |callback|
    unless callback.nil? || callback.respond_to?(:call) || (callback.respond_to?(:new) && callback.instance_methods.include?(: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



45
46
47
48
49
50
51
52
# File 'lib/rackr/router/errors.rb', line 45

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

  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:



21
22
23
24
25
# File 'lib/rackr/router/errors.rb', line 21

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