public
Description: resources_controller rails plugin: rc makes RESTful controllers fun
Homepage: http://plugins.ardes.com/doc/resources_controller
Clone URL: git://github.com/ianwhite/resources_controller.git
Click here to lend your support to: resources_controller and make a donation at www.pledgie.com !
Extracted #add_enclosing_resource from 
#load_enclosing_resource_from_specification

This makes it much easier to override #load_enclosing_resources in your 
controller if
you have a route (or set of routes) which cannot easily be mapped onto a 
specification.
mocoso (author)
Thu Oct 09 06:56:04 -0700 2008
commit  93b29a469bf994434f3e661f29fefc5f51bd4109
tree    e69ab26c055e7c34ec1775097d4c45cb9e88d2c7
parent  d82eedac75ba1eb821c50fe542df956b89be73db
...
785
786
787
788
789
790
791
792
 
793
794
795
 
 
 
 
 
 
 
 
 
796
797
798
...
785
786
787
 
 
 
 
 
788
789
790
 
791
792
793
794
795
796
797
798
799
800
801
802
0
@@ -785,14 +785,18 @@ module Ardes#:nodoc:
0
       def load_enclosing_resource_from_specification(spec)
0
         spec.segment == route_enclosing_names[enclosing_resources.size].first or ResourcesController.raise_resource_mismatch(self)
0
         returning spec.find_from(self) do |resource|
0
-          update_name_prefix(spec.name_prefix)
0
-          enclosing_resources << resource
0
-          enclosing_collection_resources << resource unless spec.singleton?
0
-          instance_variable_set("@#{spec.name}", resource)
0
-          instance_variable_set("@#{spec.as}", resource) if spec.as
0
+          add_enclosing_resource(resource, spec.name, :name_prefix => spec.name_prefix, :is_singleton => spec.singleton?, :as => spec.as )
0
         end
0
       end
0
-        
0
+      
0
+      def add_enclosing_resource(resource, name, options = {})
0
+        update_name_prefix(options[:name_prefix] || (options[:name_prefix] == false ? '' : "#{name}_"))
0
+        enclosing_resources << resource
0
+        enclosing_collection_resources << resource unless options[:is_singleton]
0
+        instance_variable_set("@#{name}", resource)
0
+        instance_variable_set("@#{options[:as]}", resource) if options[:as]
0
+      end
0
+      
0
       # The name prefix is used for forwarding urls and will be different depending on
0
       # which route the controller was invoked by.  The resource specifications build
0
       # up the name prefix as the resources are loaded.

Comments