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



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

def clear() Helpers.clear end

.define_hash_access_method(route, name) ⇒ Object



648
649
650
651
652
653
# File 'lib/action_controller/routing.rb', line 648

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



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

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

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



669
670
671
672
673
674
675
676
# File 'lib/action_controller/routing.rb', line 669

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



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

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



655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/action_controller/routing.rb', line 655

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



634
635
636
# File 'lib/action_controller/routing.rb', line 634

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