Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10646 (closed enhancement: fixed)

Opened 4 months ago

Last modified 4 months ago

[PATCH] Support for arbitrary level of module nesting in ActiveResource objects

Reported by: xavier Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveResource Version: edge
Severity: normal Keywords:
Cc:

Description

The current implementation of the private method find_or_create_resource_for in ActiveResource::Base does not find resources if their class is defined in nested modules. At the moment, it only handles a single level of namespace.

Let's say you have two resources defined in a nested module :

module Highrise
  module Resources

    class Note < ActiveResource::Base
	# ...
    end

    class Comment < ActiveResource::Base
	# ...
    end

  end
end

When you load a Note which contains a nested collection of Comments, the current implementation will actually create an array of Highrise::Resources::Note::Comment adhoc resources instead of using the existing class Highrise::Resources::Comment.

This patch addresses this problem by walking through the class namespace to find the definition of the resource. If no class is found in the nested modules, it will be created.

This patch comes with two new unit tests which ensures that the correct Resource is loaded and that ActiveResource can find classes defined at different levels in different nested modul

Attachments

activeresource_nested_modules_support.diff (3.1 kB) - added by xavier on 12/29/07 21:04:56.

Change History

12/29/07 21:04:56 changed by xavier

  • attachment activeresource_nested_modules_support.diff added.

12/29/07 21:08:24 changed by xavier

This patch is related to http://dev.rubyonrails.org/ticket/8563 which takes a different approach to tackle a similar issue.

The solution proposed here is based on introspection rather than an extra namespace parameter.

01/02/08 09:14:37 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [8525]) find_or_create_resource_for handles module nesting. Closes #10646.