Skip to content

Commit

Permalink
Extracted #add_enclosing_resource from #load_enclosing_resource_from_…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
mocoso committed Oct 9, 2008
1 parent d82eeda commit 93b29a4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/ardes/resources_controller.rb
Expand Up @@ -785,14 +785,18 @@ def load_wildcards_from(start)
def load_enclosing_resource_from_specification(spec)
spec.segment == route_enclosing_names[enclosing_resources.size].first or ResourcesController.raise_resource_mismatch(self)
returning spec.find_from(self) do |resource|
update_name_prefix(spec.name_prefix)
enclosing_resources << resource
enclosing_collection_resources << resource unless spec.singleton?
instance_variable_set("@#{spec.name}", resource)
instance_variable_set("@#{spec.as}", resource) if spec.as
add_enclosing_resource(resource, spec.name, :name_prefix => spec.name_prefix, :is_singleton => spec.singleton?, :as => spec.as )
end
end


def add_enclosing_resource(resource, name, options = {})
update_name_prefix(options[:name_prefix] || (options[:name_prefix] == false ? '' : "#{name}_"))
enclosing_resources << resource
enclosing_collection_resources << resource unless options[:is_singleton]
instance_variable_set("@#{name}", resource)
instance_variable_set("@#{options[:as]}", resource) if options[:as]
end

# The name prefix is used for forwarding urls and will be different depending on
# which route the controller was invoked by. The resource specifications build
# up the name prefix as the resources are loaded.
Expand Down

0 comments on commit 93b29a4

Please sign in to comment.