Module: ActionController::Routing::NamedRoutes
- Defined in:
- lib/action_controller/routing.rb
Overview
:nodoc:
Constant Summary collapse
- Helpers =
[]
Class Method Summary collapse
- .clear ⇒ Object
- .define_hash_access_method(route, name) ⇒ Object
- .hash_access_name(name) ⇒ Object
- .install(cls = ActionController::Base) ⇒ Object
- .known_hash_for_route(route) ⇒ Object
- .name_route(route, name) ⇒ Object
- .url_helper_name(name) ⇒ Object
Class Method Details
.clear ⇒ Object
666 |
# File 'lib/action_controller/routing.rb', line 666 def clear() Helpers.clear end |
.define_hash_access_method(route, name) ⇒ Object
686 687 688 689 690 691 |
# File 'lib/action_controller/routing.rb', line 686 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
668 669 670 |
# File 'lib/action_controller/routing.rb', line 668 def hash_access_name(name) "hash_for_#{name}_url" end |
.install(cls = ActionController::Base) ⇒ Object
707 708 709 710 711 712 713 714 |
# File 'lib/action_controller/routing.rb', line 707 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
676 677 678 679 680 681 682 683 684 |
# File 'lib/action_controller/routing.rb', line 676 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
693 694 695 696 697 698 699 700 701 702 703 704 705 |
# File 'lib/action_controller/routing.rb', line 693 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
672 673 674 |
# File 'lib/action_controller/routing.rb', line 672 def url_helper_name(name) "#{name}_url" end |