Class: Hemp::Routing::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_action, regex_match, url_variables = {}) ⇒ Route

Returns a new instance of Route.



8
9
10
11
12
# File 'lib/hemp/routing/route.rb', line 8

def initialize(controller_action, regex_match, url_variables = {})
  @controller_action = controller_action.split("#")
  @regex_match = regex_match
  @url_variables = url_variables
end

Instance Attribute Details

#controller_actionObject (readonly)

Returns the value of attribute controller_action.



6
7
8
# File 'lib/hemp/routing/route.rb', line 6

def controller_action
  @controller_action
end

#regex_matchObject (readonly)

Returns the value of attribute regex_match.



6
7
8
# File 'lib/hemp/routing/route.rb', line 6

def regex_match
  @regex_match
end

#url_variablesObject (readonly)

Returns the value of attribute url_variables.



6
7
8
# File 'lib/hemp/routing/route.rb', line 6

def url_variables
  @url_variables
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/hemp/routing/route.rb', line 48

def ==(other)
  (regex_match =~ other) == 0
end

#actionObject



18
19
20
# File 'lib/hemp/routing/route.rb', line 18

def action
  @controller_action[1]
end

#action_symObject



30
31
32
# File 'lib/hemp/routing/route.rb', line 30

def action_sym
  action.to_sym
end

#controllerObject



14
15
16
# File 'lib/hemp/routing/route.rb', line 14

def controller
  @controller_action[0]
end

#controller_camelObject



26
27
28
# File 'lib/hemp/routing/route.rb', line 26

def controller_camel
  controller_class.camelcase :upper
end

#controller_classObject



22
23
24
# File 'lib/hemp/routing/route.rb', line 22

def controller_class
  controller + "_controller"
end

#controller_snakeObject



34
35
36
# File 'lib/hemp/routing/route.rb', line 34

def controller_snake
  controller_class.snakecase
end

#get_url_vars(path_info) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/hemp/routing/route.rb', line 38

def get_url_vars(path_info)
  path_elements = path_info.split("/")
  var_collection = {}
  url_variables.each_key do |index|
    var_collection[url_variables[index]] = path_elements[index]
  end

  var_collection
end