happymapper
happymapper copied to clipboard
wrap doesn't work for custom getter
For this example:
require 'happymapper'
class Root
include HappyMapper
tag 'Working'
element :name, String
wrap 'mywraptag' do
element :description, String
element :number, Integer
end
element :code, String
def description
'wooo'
end
def code
'ABC123'
end
end
root = Root.new
root.number = 12_345
puts root.to_xml
I have the following output:
<?xml version="1.0"?>
<Working>
<mywraptag>
<number>12345</number>
</mywraptag>
<code>ABC123</code>
</Working>
but if I comment the description
method, and set the attribute like I do for the number
it will generate the wrap tag as expected.
In my case I'm using those defined methods to get some fields from database objects, so I must admit that this could probably be not the most common scenario. Even though as far as I understand if should work.