representable
representable copied to clipboard
Nested property using (attribute: true) returns "NoMethodError: undefined method"
Hey there,
i have some trouble with the property/attribute option. For example:
<foo>
<bar />
</foo>
instead of the expected one:
<foo>
<bar title="this is my title" />
</foo>
and a mapping like this:
nested 'foo'
nested 'bar' do
property 'title', attribute: true,
setter: ->(fragment:, represented:, **) { ... }
end
end
end
With this i get an Error NoMethodError: undefined method `title=' for #<Hash:0x00000006df7590>. I can solve this by adding a reader and skip_parse:
nested 'foo'
nested 'bar' do
property 'title', attribute: true,
reader: ->(doc:, **){ doc[:title] || ''},
skip_parse: fragment_empty,
setter: ->(fragment:, represented:, **) { ... }
end
end
end
Isn't there a way to skip this by default? If the attribute does not exists just skip instead of the exception?
Any ideas?
Can you check if that problem persists with Representable::Hash instead of XML? Looks to me like an XML problem.