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



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

def clear() Helpers.clear end

.define_hash_access_method(route, name) ⇒ Object



682
683
684
685
686
687
# File 'lib/action_controller/routing.rb', line 682

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



664
665
666
# File 'lib/action_controller/routing.rb', line 664

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

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



703
704
705
706
707
708
709
710
# File 'lib/action_controller/routing.rb', line 703

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



672
673
674
675
676
677
678
679
680
# File 'lib/action_controller/routing.rb', line 672

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



689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/action_controller/routing.rb', line 689

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



668
669
670
# File 'lib/action_controller/routing.rb', line 668

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