Class: ActionController::Routing::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/routing.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Route

Returns a new instance of Route.



303
304
305
306
307
308
309
310
311
312
# File 'lib/action_controller/routing.rb', line 303

def initialize(path, options = {})
  @path, @options = path, options
    
  initialize_components path
  defaults, conditions = initialize_hashes options.dup
  @defaults = defaults.dup
  configure_components(defaults, conditions)
  add_default_requirements
  initialize_keys
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



300
301
302
# File 'lib/action_controller/routing.rb', line 300

def components
  @components
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



301
302
303
# File 'lib/action_controller/routing.rb', line 301

def defaults
  @defaults
end

#keysObject (readonly)

Returns the value of attribute keys.



301
302
303
# File 'lib/action_controller/routing.rb', line 301

def keys
  @keys
end

#knownObject

Returns the value of attribute known.



300
301
302
# File 'lib/action_controller/routing.rb', line 300

def known
  @known
end

#optionsObject (readonly)

Returns the value of attribute options.



301
302
303
# File 'lib/action_controller/routing.rb', line 301

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



301
302
303
# File 'lib/action_controller/routing.rb', line 301

def path
  @path
end

Instance Method Details

#extra_keys(options) ⇒ Object



356
357
358
# File 'lib/action_controller/routing.rb', line 356

def extra_keys(options)
  options.keys - @keys
end

#initialize_keysObject



351
352
353
354
# File 'lib/action_controller/routing.rb', line 351

def initialize_keys
  @keys = (components.collect {|c| c.key} + known.keys).compact
  @keys.freeze
end

#inspectObject



314
315
316
# File 'lib/action_controller/routing.rb', line 314

def inspect
  "<#{self.class} #{path.inspect}, #{options.inspect[1..-1]}>"
end

#matches_controller?(controller) ⇒ Boolean

Returns:

  • (Boolean)


360
361
362
363
364
365
366
367
# File 'lib/action_controller/routing.rb', line 360

def matches_controller?(controller)
  if known[:controller] then known[:controller] == controller
  else
    c = components.find {|c| c.key == :controller}
    return false unless c
    return c.condition.nil? || eval(Routing.test_condition('controller', c.condition))
  end
end

#write_generation(generator = CodeGeneration::GenerationGenerator.new) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/action_controller/routing.rb', line 318

def write_generation(generator = CodeGeneration::GenerationGenerator.new)
  generator.before, generator.current, generator.after = [], components.first, (components[1..-1] || [])

  if known.empty? then generator.go
  else
    # Alter the conditions to allow :action => 'index' to also catch :action => nil
    altered_known = known.collect do |k, v|
      if k == :action && v== 'index' then [k, [nil, 'index']]
      else [k, v]
      end
    end
    generator.if(generator.check_conditions(altered_known)) {|gp| gp.go }
  end
  
  generator
end

#write_recognition(generator = CodeGeneration::RecognitionGenerator.new) ⇒ Object



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/action_controller/routing.rb', line 335

def write_recognition(generator = CodeGeneration::RecognitionGenerator.new)
  g = generator.dup
  g.share_locals_with generator
  g.before, g.current, g.after = [], components.first, (components[1..-1] || [])
    
  known.each do |key, value|
    if key == :controller then ControllerComponent.assign_controller(g, value)
    else g.constant_result(key, value)
    end
  end
    
  g.go
    
  generator
end