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
635 |
# File 'lib/action_controller/routing.rb', line 635 def clear() Helpers.clear end |
.define_hash_access_method(route, name) ⇒ Object
655 656 657 658 659 660 |
# File 'lib/action_controller/routing.rb', line 655 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
637 638 639 |
# File 'lib/action_controller/routing.rb', line 637 def hash_access_name(name) "hash_for_#{name}_url" end |
.install(cls = ActionController::Base) ⇒ Object
676 677 678 679 680 681 682 683 |
# File 'lib/action_controller/routing.rb', line 676 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
645 646 647 648 649 650 651 652 653 |
# File 'lib/action_controller/routing.rb', line 645 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
662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/action_controller/routing.rb', line 662 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
641 642 643 |
# File 'lib/action_controller/routing.rb', line 641 def url_helper_name(name) "#{name}_url" end |