Module: ActionController::Routing

Defined in:
lib/action_controller/routing.rb

Overview

:nodoc:

Defined Under Namespace

Modules: NamedRoutes Classes: Component, ControllerComponent, DynamicComponent, PathComponent, Route, RouteSet, StaticComponent

Constant Summary collapse

Routes =
RouteSet.new

Class Method Summary collapse

Class Method Details

.controller_relative_to(controller, previous) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/action_controller/routing.rb', line 14

def controller_relative_to(controller, previous)
  if controller.nil?           then previous
  elsif controller[0] == ?/    then controller[1..-1]
  elsif %r{^(.*)/} =~ previous then "#{$1}/#{controller}"
  else controller
  end
end

.expiry_hash(options, recall) ⇒ Object



4
5
6
7
8
9
# File 'lib/action_controller/routing.rb', line 4

def expiry_hash(options, recall)
  k = v = nil
  expire_on = {}
  options.each {|k, v| expire_on[k] = ((rcv = recall[k]) && (rcv != v))}
  expire_on
end

.extract_parameter_value(parameter) ⇒ Object

:nodoc:



11
12
13
# File 'lib/action_controller/routing.rb', line 11

def extract_parameter_value(parameter) #:nodoc:
  CGI.escape((parameter.respond_to?(:to_param) ? parameter.to_param : parameter).to_s) 
end

.test_condition(expression, condition) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/action_controller/routing.rb', line 34

def test_condition(expression, condition)
  case condition
    when String then "(#{expression} == #{condition.inspect})"
    when Regexp then
      condition = Regexp.new("^#{condition.source}$") unless /^\^.*\$$/ =~ condition.source 
      "(#{condition.inspect} =~ #{expression})"
    when Array then
      conds = condition.collect do |condition|
        cond = test_condition(expression, condition)
        (cond[0, 1] == '(' && cond[-1, 1] == ')') ? cond : "(#{cond})"
      end
      "(#{conds.join(' || ')})"
    when true then expression
    when nil then "! #{expression}"
    else
      raise ArgumentError, "Valid criteria are strings, regular expressions, true, or nil"
  end
end

.treat_hash(hash, keys_to_delete = []) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/action_controller/routing.rb', line 22

def treat_hash(hash, keys_to_delete = [])
  k = v = nil
  hash.each do |k, v|
    if v then hash[k] = (v.respond_to? :to_param) ? v.to_param.to_s : v.to_s
    else
      hash.delete k
      keys_to_delete << k
    end
  end
  hash
end