class Pup::Routing::Route

Attributes

action[R]
controller_name[R]
path_regex[R]
url_placeholders[R]

Public Class Methods

new(path_regex, to, url_placeholders = {}) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# 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) click to toggle source
# File lib/pup/routing/route.rb, line 30
def check_path(path)
  (path_regex =~ path) == 0
end
controller() click to toggle source
# File lib/pup/routing/route.rb, line 17
def controller
  Object.const_get(controller_name.to_camelcase)
end
get_url_parameters(actual_path) click to toggle source
# 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

Private Instance Methods

get_controller_and_action(to) click to toggle source
# File lib/pup/routing/route.rb, line 11
def get_controller_and_action(to)
  controller, action = to.split("#")
  controller_name = controller + "_controller"
  [controller_name, action]
end