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

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

Open
skorth opened this issue Nov 2, 2016 · 1 comment

Comments

@skorth
Copy link

skorth commented Nov 2, 2016

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?

@apotonick
Copy link
Member

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

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

No branches or pull requests

2 participants