Module: ActionController::Routing::NamedRoutes

Defined in:
lib/action_controller/routing.rb

Overview

:nodoc:

Constant Summary collapse

Helpers =
[]

Class Method Summary collapse

Class Method Details

.clearObject



609
# File 'lib/action_controller/routing.rb', line 609

def clear() Helpers.clear end

.define_hash_access_method(route, name) ⇒ Object



629
630
631
632
633
634
# File 'lib/action_controller/routing.rb', line 629

def define_hash_access_method(route, name)
  hash = known_hash_for_route(route)
  define_method(hash_access_name(name)) do |*args|
    args.first ? hash.merge(args.first) : hash
  end
end

.hash_access_name(name) ⇒ Object



611
612
613
# File 'lib/action_controller/routing.rb', line 611

def hash_access_name(name)
  "hash_for_#{name}_url"
end

.install(cls = ActionController::Base) ⇒ Object



650
651
652
653
654
655
656
657
# File 'lib/action_controller/routing.rb', line 650

def install(cls = ActionController::Base)
  cls.send :include, self
  if cls.respond_to? :helper_method
    Helpers.each do |helper_name|
      cls.send :helper_method, helper_name
    end
  end
end

.known_hash_for_route(route) ⇒ Object



619
620
621
622
623
624
625
626
627
# File 'lib/action_controller/routing.rb', line 619

def known_hash_for_route(route)
  hash = route.known.symbolize_keys
  route.defaults.each do |key, value|
    hash[key.to_sym] ||= value if value
  end
  hash[:controller] = "/#{hash[:controller]}"
  
  hash
end

.name_route(route, name) ⇒ Object



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/action_controller/routing.rb', line 636

def name_route(route, name)
  define_hash_access_method(route, name)
  
  module_eval(%{def #{url_helper_name name}(options = {})
    url_for(#{hash_access_name(name)}.merge(options))
  end}, "generated/routing/named_routes/#{name}.rb")
      
  protected url_helper_name(name), hash_access_name(name)
      
  Helpers << url_helper_name(name).to_sym
  Helpers << hash_access_name(name).to_sym
  Helpers.uniq!
end

.url_helper_name(name) ⇒ Object



615
616
617
# File 'lib/action_controller/routing.rb', line 615

def url_helper_name(name)
  "#{name}_url"
end