Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object_root for each object in collection #295

Open
GarPit opened this issue Jul 21, 2012 · 3 comments
Open

object_root for each object in collection #295

GarPit opened this issue Jul 21, 2012 · 3 comments

Comments

@GarPit
Copy link

GarPit commented Jul 21, 2012

Let's assume I have a collection with different object classes (STI). For example, I have a "Whoot" base class and "ReWhoot" as subclass and my API returns both Whoots and Rewhoots in a single collection.

Output for xml version looks like this:

<rewhoots type="array">
  <rewhoot>
  ..
  </rewhoot>
  <rewhoot>
  ...

But actually second object is instance of Whoot and it will be nice to output this node as

<whoot>..</whoot>

options[:root_name] is calculated only once and used for any object

  def compile_hash(options={})
    ....
    # Wrap result in root
    if options[:root_name].present?
      @_root_name = options[:root_name]
    else # no root
      @_root_name = nil
    end

It will be cool if we could call "class.model_name" or just "class.to_s" on each object (i.e. something like this):

def compile_hash(options={})
    ....
    # Wrap result in root
    if options[:root_name].present?
      @_root_name = options[:root_name]
    else # no root
      @_root_name = determine_object_root(@_object, options[:root])
    end
@databyte
Copy link
Collaborator

I'm not using XML output in production anywhere so if you can submit a patch with tests, I'll gladly review it.

There are tests for everything in the engine and builder in the root test suite but also both JSON and XML output tests in the rails3_2 fixture under fixtures/rails3_2/test/functional/. Though I added the XML ones, it was just for caching so if you need to expand those - I'd be happy to receive those as well.

@nesquena
Copy link
Owner

nesquena commented Aug 8, 2012

Yes, I suspect xml needs some love. If anyone can help by adding failing tests that would make it really easy for us to investigate.

@databyte
Copy link
Collaborator

Leaving open. XML does need love in v1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants