Class: Pup::Routing::Route

Inherits:
Object show all
Defined in:
lib/pup/routing/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject (readonly)

Returns the value of attribute action.



4
5
6
# File 'lib/pup/routing/route.rb', line 4

def action
  @action
end

#controller_nameObject (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_regexObject (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_placeholdersObject (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

#controllerObject



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