ActiveRecord's to_xml method has a :dasherize option to control
name formatting - this patch allows passing a :camelize option to
CamelCase names as well.
>> c = Contact.new({:my_name => "Bob"})
=> #<Contact id: nil, my_name: "Bob", created_at: nil, updated_at: nil>
>> c.to_xml :camelize => true
=> "<?xml version="1.0" encoding="UTF-8"?>
<Contact>
<CreatedAt type="datetime" nil="true"></CreatedAt>
<MyName>Bob</MyName>
<UpdatedAt type="datetime" nil="true"></UpdatedAt>
</Contact>
"
>>
This works just like the :dasherize option. :camelize is false
by default - setting it to true will also override any :dasherize
settings (since it's not clear that you would ever want a
Camel-Cased name).
Docs and tests are in the patch - to make this work I applied
the change into ActiveSupport's Hash Conversions (for
ActiveRecord.from_xml to work) and applied it to Hash.to_xml (in
order to get tests to work).
I needed this on a project which needed CamelCased XML output
names so I figured there's probably others who need the same thing.
This is my first patch so please let me know if I'm missing
anything else I need to think about/include.