Class: Pup::Routing::Router

Inherits:
Object show all
Includes:
Pup::RouteHelpers
Defined in:
lib/pup/routing/router.rb

Constant Summary collapse

ALLOWED_VERBS =
%w(get post put patch delete).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pup::RouteHelpers

#resources, #root

Constructor Details

#initializeRouter

Returns a new instance of Router.



12
13
14
15
16
17
# File 'lib/pup/routing/router.rb', line 12

def initialize
  @routes = {}
  @url_placeholders = {}
  @part_regex = []
  generate_verb_methods
end

Instance Attribute Details

#part_regexObject

Returns the value of attribute part_regex.



8
9
10
# File 'lib/pup/routing/router.rb', line 8

def part_regex
  @part_regex
end

#routesObject

Returns the value of attribute routes.



8
9
10
# File 'lib/pup/routing/router.rb', line 8

def routes
  @routes
end

#url_placeholdersObject

Returns the value of attribute url_placeholders.



8
9
10
# File 'lib/pup/routing/router.rb', line 8

def url_placeholders
  @url_placeholders
end

Instance Method Details

#create(&block) ⇒ Object



19
20
21
# File 'lib/pup/routing/router.rb', line 19

def create(&block)
  instance_eval(&block)
end

#get_match(verb, path) ⇒ Object



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

def get_match(verb, path)
  verb = verb.downcase
  routes[verb].detect do |route|
    route.check_path(path)
  end
end

#has_routes?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pup/routing/router.rb', line 23

def has_routes?
  true unless routes.empty?
end