Class: Pup::Routing::Router
- 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
-
#part_regex ⇒ Object
Returns the value of attribute part_regex.
-
#routes ⇒ Object
Returns the value of attribute routes.
-
#url_placeholders ⇒ Object
Returns the value of attribute url_placeholders.
Instance Method Summary collapse
- #create(&block) ⇒ Object
- #get_match(verb, path) ⇒ Object
- #has_routes? ⇒ Boolean
-
#initialize ⇒ Router
constructor
A new instance of Router.
Methods included from Pup::RouteHelpers
Constructor Details
#initialize ⇒ Router
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_regex ⇒ Object
Returns the value of attribute part_regex.
8 9 10 |
# File 'lib/pup/routing/router.rb', line 8 def part_regex @part_regex end |
#routes ⇒ Object
Returns the value of attribute routes.
8 9 10 |
# File 'lib/pup/routing/router.rb', line 8 def routes @routes end |
#url_placeholders ⇒ Object
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
23 24 25 |
# File 'lib/pup/routing/router.rb', line 23 def has_routes? true unless routes.empty? end |