representable icon indicating copy to clipboard operation
representable copied to clipboard

Nested property using (attribute: true) returns "NoMethodError: undefined method"

Open skorth opened this issue 9 years ago • 1 comments

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?

skorth avatar Nov 02 '16 10:11 skorth

Can you check if that problem persists with Representable::Hash instead of XML? Looks to me like an XML problem.

apotonick avatar Nov 02 '16 10:11 apotonick