solnic / virtus

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

attribute types definitions and top level class names clashes. #234

Closed codesnik closed 9 years ago

codesnik commented 10 years ago

This is a quite subtle problem. I'll try to illustrate:

require 'virtus'
require 'mongoid'
class Foo
  include Virtus.model
  attribute :bar, Boolean
end
Foo.new(bar: 1).bar # => 1

Mongoid defines it's own ::Boolean class, and that was enough to silently break coercer.

This is probably a mongoid problem, it's quite dirty. But it raises a question if attribute type declaration magic is magic enough. Thoughts?

solnic commented 10 years ago

This is a known issue. Maybe I should document it. /cc @elskwid

elskwid commented 10 years ago

@solnic, I've labelled it for docs and assigned it to myself.

acook commented 10 years ago

@codesnik This will address the correct class:

require 'virtus'
require 'mongoid'

class Foo
  include Virtus.model
  attribute :bar, Virtus::Attribute::Boolean
end
Foo.new(bar: 1).bar # => 1
borama commented 7 years ago

@solnic I think that the documentation in the README, that was added when closing this PR, is actually wrong.

Here, @acook says to use the Virtus::Attribute::Boolean class for explicitly specifying the Boolean type but in the README there is Axiom::Types::Boolean suggested. I believe that this causes problems that are described in this StackOverflow question, which seem to be fixed by using the Virtus::Attribute::Boolean class indeed.

Can you confirm the correct form, please?

solnic commented 7 years ago

Sorry, I no longer maintain virtus.