Class: Pup::Routing::Route
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller_name ⇒ Object
readonly
Returns the value of attribute controller_name.
-
#path_regex ⇒ Object
readonly
Returns the value of attribute path_regex.
-
#url_placeholders ⇒ Object
readonly
Returns the value of attribute url_placeholders.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #check_path(path) ⇒ Object
- #controller ⇒ Object
- #get_url_parameters(actual_path) ⇒ Object
-
#initialize(path_regex, to, url_placeholders = {}) ⇒ Route
constructor
A new instance of Route.
Constructor Details
#initialize(path_regex, to, url_placeholders = {}) ⇒ Route
5 6 7 8 9 |
# File 'lib/pup/routing/route.rb', line 5 def initialize(path_regex, to, url_placeholders = {}) @controller_name, @action = get_controller_and_action(to) @path_regex = path_regex @url_placeholders = url_placeholders end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/pup/routing/route.rb', line 4 def action @action end |
#controller_name ⇒ Object (readonly)
Returns the value of attribute controller_name.
4 5 6 |
# File 'lib/pup/routing/route.rb', line 4 def controller_name @controller_name end |
#path_regex ⇒ Object (readonly)
Returns the value of attribute path_regex.
4 5 6 |
# File 'lib/pup/routing/route.rb', line 4 def path_regex @path_regex end |
#url_placeholders ⇒ Object (readonly)
Returns the value of attribute url_placeholders.
4 5 6 |
# File 'lib/pup/routing/route.rb', line 4 def url_placeholders @url_placeholders end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/pup/routing/route.rb', line 34 def ==(other) controller_name == other.controller_name && action == other.action && path_regex == other.path_regex && url_placeholders == other.url_placeholders end |
#check_path(path) ⇒ Object
30 31 32 |
# File 'lib/pup/routing/route.rb', line 30 def check_path(path) (path_regex =~ path) == 0 end |
#controller ⇒ Object
17 18 19 |
# File 'lib/pup/routing/route.rb', line 17 def controller Object.const_get(controller_name.to_camelcase) end |
#get_url_parameters(actual_path) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/pup/routing/route.rb', line 21 def get_url_parameters(actual_path) parameters = {} path = actual_path.split("/") url_placeholders.each do |index, key| parameters[key] = path[index.to_i] end parameters end |