Class Index [+]

Quicksearch

ActionDispatch::Routing::Mapper::Resources

Constants

VALID_ON_OPTIONS

CANONICAL_ACTIONS holds all actions that does not need a prefix or a path appended since they fit properly in their scope level.

RESOURCE_OPTIONS
CANONICAL_ACTIONS

Public Instance Methods

collection() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 611
611:         def collection
612:           unless @scope[:scope_level] == :resources
613:             raise ArgumentError, "can't use collection outside resources scope"
614:           end
615: 
616:           collection_scope do
617:             yield
618:           end
619:         end
match(*args) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 681
681:         def match(*args)
682:           options = args.extract_options!.dup
683:           options[:anchor] = true unless options.key?(:anchor)
684: 
685:           if args.length > 1
686:             args.each { |path| match(path, options.dup) }
687:             return self
688:           end
689: 
690:           on = options.delete(:on)
691:           if VALID_ON_OPTIONS.include?(on)
692:             args.push(options)
693:             return send(on){ match(*args) }
694:           elsif on
695:             raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
696:           end
697: 
698:           if @scope[:scope_level] == :resources
699:             args.push(options)
700:             return nested { match(*args) }
701:           elsif @scope[:scope_level] == :resource
702:             args.push(options)
703:             return member { match(*args) }
704:           end
705: 
706:           action = args.first
707:           path = path_for_action(action, options.delete(:path))
708: 
709:           if action.to_s =~ /^[\w\/]+$/
710:             options[:action] ||= action unless action.to_s.include?("/")
711:             options[:as] = name_for_action(action, options[:as])
712:           else
713:             options[:as] = name_for_action(options[:as])
714:           end
715: 
716:           super(path, options)
717:         end
member() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 621
621:         def member
622:           unless resource_scope?
623:             raise ArgumentError, "can't use member outside resource(s) scope"
624:           end
625: 
626:           member_scope do
627:             yield
628:           end
629:         end
namespace(path, options = {}) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 663
663:         def namespace(path, options = {})
664:           if resource_scope?
665:             nested { super }
666:           else
667:             super
668:           end
669:         end
nested() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 641
641:         def nested
642:           unless resource_scope?
643:             raise ArgumentError, "can't use nested outside resource(s) scope"
644:           end
645: 
646:           with_scope_level(:nested) do
647:             if shallow?
648:               with_exclusive_scope do
649:                 if @scope[:shallow_path].blank?
650:                   scope(parent_resource.nested_scope, nested_options) { yield }
651:                 else
652:                   scope(@scope[:shallow_path], :as => @scope[:shallow_prefix]) do
653:                     scope(parent_resource.nested_scope, nested_options) { yield }
654:                   end
655:                 end
656:               end
657:             else
658:               scope(parent_resource.nested_scope, nested_options) { yield }
659:             end
660:           end
661:         end
new() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 631
631:         def new
632:           unless resource_scope?
633:             raise ArgumentError, "can't use new outside resource(s) scope"
634:           end
635: 
636:           new_scope do
637:             yield
638:           end
639:         end
resource(*resources, &block) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 552
552:         def resource(*resources, &block)
553:           options = resources.extract_options!
554: 
555:           if apply_common_behavior_for(:resource, resources, options, &block)
556:             return self
557:           end
558: 
559:           resource_scope(SingletonResource.new(resources.pop, options)) do
560:             yield if block_given?
561: 
562:             collection_scope do
563:               post :create
564:             end if parent_resource.actions.include?(:create)
565: 
566:             new_scope do
567:               get :new
568:             end if parent_resource.actions.include?(:new)
569: 
570:             member_scope  do
571:               get    :edit if parent_resource.actions.include?(:edit)
572:               get    :show if parent_resource.actions.include?(:show)
573:               put    :update if parent_resource.actions.include?(:update)
574:               delete :destroy if parent_resource.actions.include?(:destroy)
575:             end
576:           end
577: 
578:           self
579:         end
resources(*resources, &block) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 581
581:         def resources(*resources, &block)
582:           options = resources.extract_options!
583: 
584:           if apply_common_behavior_for(:resources, resources, options, &block)
585:             return self
586:           end
587: 
588:           resource_scope(Resource.new(resources.pop, options)) do
589:             yield if block_given?
590: 
591:             collection_scope do
592:               get  :index if parent_resource.actions.include?(:index)
593:               post :create if parent_resource.actions.include?(:create)
594:             end
595: 
596:             new_scope do
597:               get :new
598:             end if parent_resource.actions.include?(:new)
599: 
600:             member_scope  do
601:               get    :edit if parent_resource.actions.include?(:edit)
602:               get    :show if parent_resource.actions.include?(:show)
603:               put    :update if parent_resource.actions.include?(:update)
604:               delete :destroy if parent_resource.actions.include?(:destroy)
605:             end
606:           end
607: 
608:           self
609:         end
resources_path_names(options) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 548
548:         def resources_path_names(options)
549:           @scope[:path_names].merge!(options)
550:         end
root(options={}) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 719
719:         def root(options={})
720:           if @scope[:scope_level] == :resources
721:             with_scope_level(:root) do
722:               scope(parent_resource.path) do
723:                 super(options)
724:               end
725:             end
726:           else
727:             super(options)
728:           end
729:         end
shallow() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 671
671:         def shallow
672:           scope(:shallow => true) do
673:             yield
674:           end
675:         end
shallow?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 677
677:         def shallow?
678:           parent_resource.instance_of?(Resource) && @scope[:shallow]
679:         end

Protected Instance Methods

action_options?(options) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 769
769:           def action_options?(options)
770:             options[:only] || options[:except]
771:           end
action_path(name, path = nil) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 877
877:           def action_path(name, path = nil)
878:             path || @scope[:path_names][name.to_sym] || name.to_s
879:           end
apply_common_behavior_for(method, resources, options, &block) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 737
737:           def apply_common_behavior_for(method, resources, options, &block)
738:             if resources.length > 1
739:               resources.each { |r| send(method, r, options, &block) }
740:               return true
741:             end
742: 
743:             options.keys.each do |k|
744:               (options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp)
745:             end
746: 
747:             scope_options = options.slice!(*RESOURCE_OPTIONS)
748:             unless scope_options.empty?
749:               scope(scope_options) do
750:                 send(method, resources.pop, options, &block)
751:               end
752:               return true
753:             end
754: 
755:             unless action_options?(options)
756:               options.merge!(scope_action_options) if scope_action_options?
757:             end
758: 
759:             if resource_scope?
760:               nested do
761:                 send(method, resources.pop, options, &block)
762:               end
763:               return true
764:             end
765: 
766:             false
767:           end
canonical_action?(action, flag) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 858
858:           def canonical_action?(action, flag)
859:             flag && resource_method_scope? && CANONICAL_ACTIONS.include?(action.to_s)
860:           end
collection_scope() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 827
827:           def collection_scope
828:             with_scope_level(:collection) do
829:               scope(parent_resource.collection_scope) do
830:                 yield
831:               end
832:             end
833:           end
id_constraint() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 854
854:           def id_constraint
855:             @scope[:id] || @scope[:constraints][:id]
856:           end
id_constraint?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 850
850:           def id_constraint?
851:             @scope[:id].is_a?(Regexp) || (@scope[:constraints] && @scope[:constraints][:id].is_a?(Regexp))
852:           end
member_scope() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 835
835:           def member_scope
836:             with_scope_level(:member) do
837:               scope(parent_resource.member_scope) do
838:                 yield
839:               end
840:             end
841:           end
name_for_action(action, as=nil) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 891
891:           def name_for_action(action, as=nil)
892:             prefix = prefix_name_for_action(action, as)
893:             prefix = Mapper.normalize_name(prefix) if prefix
894:             name_prefix = @scope[:as]
895: 
896:             if parent_resource
897:               collection_name = parent_resource.collection_name
898:               member_name = parent_resource.member_name
899:             end
900: 
901:             name = case @scope[:scope_level]
902:             when :nested
903:               [member_name, prefix]
904:             when :collection
905:               [prefix, name_prefix, collection_name]
906:             when :new
907:               [prefix, :new, name_prefix, member_name]
908:             when :member
909:               [prefix, shallow_scoping? ? @scope[:shallow_prefix] : name_prefix, member_name]
910:             when :root
911:               [name_prefix, collection_name, prefix]
912:             else
913:               [name_prefix, member_name, prefix]
914:             end
915: 
916:             name.select(&:present?).join("_").presence
917:           end
nested_options() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 843
843:           def nested_options
844:             {}.tap do |options|
845:               options[:as] = parent_resource.member_name
846:               options[:constraints] = { "#{parent_resource.singular}_id".to_sym => id_constraint } if id_constraint?
847:             end
848:           end
new_scope() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 819
819:           def new_scope
820:             with_scope_level(:new) do
821:               scope(parent_resource.new_scope(action_path(:new))) do
822:                 yield
823:               end
824:             end
825:           end
path_for_action(action, path) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 866
866:           def path_for_action(action, path)
867:             prefix = shallow_scoping? ?
868:               "#{@scope[:shallow_path]}/#{parent_resource.path}/:id" : @scope[:path]
869: 
870:             path = if canonical_action?(action, path.blank?)
871:               prefix.to_s
872:             else
873:               "#{prefix}/#{action_path(action, path)}"
874:             end
875:           end
prefix_name_for_action(action, as) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 881
881:           def prefix_name_for_action(action, as)
882:             if as.present?
883:               as.to_s
884:             elsif as
885:               nil
886:             elsif !canonical_action?(action, @scope[:scope_level])
887:               action.to_s
888:             end
889:           end
resource_method_scope?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 785
785:           def resource_method_scope?
786:             [:collection, :member, :new].include?(@scope[:scope_level])
787:           end
resource_scope(resource) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 811
811:           def resource_scope(resource)
812:             with_scope_level(resource.is_a?(SingletonResource) ? :resource : :resources, resource) do
813:               scope(parent_resource.resource_scope) do
814:                 yield
815:               end
816:             end
817:           end
resource_scope?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 781
781:           def resource_scope?
782:             [:resource, :resources].include?(@scope[:scope_level])
783:           end
scope_action_options() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 777
777:           def scope_action_options
778:             @scope[:options].slice(:only, :except)
779:           end
scope_action_options?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 773
773:           def scope_action_options?
774:             @scope[:options].is_a?(Hash) && (@scope[:options][:only] || @scope[:options][:except])
775:           end
shallow_scoping?() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 862
862:           def shallow_scoping?
863:             shallow? && @scope[:scope_level] == :member
864:           end
with_exclusive_scope() click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 789
789:           def with_exclusive_scope
790:             begin
791:               old_name_prefix, old_path = @scope[:as], @scope[:path]
792:               @scope[:as], @scope[:path] = nil, nil
793: 
794:               with_scope_level(:exclusive) do
795:                 yield
796:               end
797:             ensure
798:               @scope[:as], @scope[:path] = old_name_prefix, old_path
799:             end
800:           end
with_scope_level(kind, resource = parent_resource) click to toggle source
     # File lib/action_dispatch/routing/mapper.rb, line 802
802:           def with_scope_level(kind, resource = parent_resource)
803:             old, @scope[:scope_level] = @scope[:scope_level], kind
804:             old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
805:             yield
806:           ensure
807:             @scope[:scope_level] = old
808:             @scope[:scope_level_resource] = old_resource
809:           end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.