Skip to content

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.

2 participants