Module: Rackr::Router::Errors

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

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.check_as(as, path) ⇒ Object



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

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



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

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



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

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:



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

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_scope_name(path) ⇒ Object



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

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



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

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