solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Fixed determining Boolean from `false` #378

Open ktimothy opened 7 years ago

ktimothy commented 7 years ago

This is a small hack, that fixes incorrect behaviour in #377.

The problem, as I see it, is that Virtus::Attribute::Boolean has only TrueClass as a primitive. This makes Virtus::TypeLookup to determine correctly only true, because it executes TrueClass >= true.class. The same expression with false - TrueClass >= false.class will not allow TypeLookup to think that false is somehow connected to Virtus::Attribute::Boolean.

I replaced TrueClass primitive with BooleanPrimitive, that returns true when comparing with both TrueClass and FalseClass, thus allowing TypeLookup to connect true and false values with Virtus::Attribute::Boolean.

ktimothy commented 7 years ago

@elskwid could you please take a look?

ktimothy commented 7 years ago

@elskwid any thoughts? =)

dblock commented 5 years ago

This got re-raised in https://github.com/ruby-grape/grape/issues/1577. Maybe someone cares to merge this? Thank you!

dblock commented 5 years ago

I just read the discontinued note. Sad to see Virtus go, thanks @solnic for your hard work. We'll move off it eventually.