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

Adds support for nested elements named 'class' #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Confusion
Copy link

@Confusion Confusion commented Nov 29, 2019

Defining an item named 'class', as in

class Msg
  include HappyMapper

  has_one :'class', String
end

Msg.parse('<msg></msg>')

currently fails with
lib/happymapper.rb:489:in initialize': undefined method attributes' for nil:NilClass (NoMethodError)

The reason is that the .class method of the HappyMapper object is
overridden and all uses of self.class, starting with the one in
initialize, will fail.

The spec modification in this commit demonstrates another aspect of this
problem (when applied without the other changes) and can serve as a guard
against regression.

The fix is to add __class__ as an alias of class. Of course, if anyone ever
needs __class__ as an item, they will run into the same problem.
However, a generic solution adds a lot more complexity and needing __class__
is (much?) less likely than 'class'.

Defining an item named 'class', as in
```
class Msg
  include HappyMapper

  has_one :'class', String
end

Msg.parse('<msg></msg>')
```
currently fails with
`lib/happymapper.rb:489:in `initialize': undefined method `attributes' for nil:NilClass (NoMethodError)`

The reason is that the .class method of the HappyMapper object is
overridden and all uses of self.class, starting with the one in
`initialize`, will fail.

The spec modification in this commit demonstrates another aspect of this
problem (when applied without the other changes) and can serve as a guard
against regression.

The fix is to add __class__ as an alias of class. Of course, if anyone ever
needs __class__ as an item, they will run into the same problem.
However, a generic solution adds a lot more complexity and needing __class__
is (much?) less likely than 'class'.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 76

  • 13 of 13 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 98.54%

Totals Coverage Status
Change from base Build 75: 0.004%
Covered Lines: 405
Relevant Lines: 411

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

None yet

2 participants