class Value
include Virtus.value_object
attribute :number, Integer
end
We expect: Value.new(:number => 7) == Value.new(:number => 7)
This behavior works as expected when using the deprecated include Virtus::ValueObject but is not preserved with the newer include. The equality behavior seems to be provided by ValueObject::ClassMethods which does not get extended when a value object class is constructed using the builder.
I took a quick crack at correcting the issue but I'm pretty sure I'm going down the wrong path. Including the class methods fixes equality but seems to introduce conflicting ideas about how to set options on attributes. Can you provide some guidance?
You need to wrap attribute definitions in a values do .. end block. That's horrible I have to admit so it's going away in Virtus 2.0. Sorry about that.
Given:
We expect:
Value.new(:number => 7) == Value.new(:number => 7)
This behavior works as expected when using the deprecated
include Virtus::ValueObject
but is not preserved with the newer include. The equality behavior seems to be provided byValueObject::ClassMethods
which does not get extended when a value object class is constructed using the builder.I took a quick crack at correcting the issue but I'm pretty sure I'm going down the wrong path. Including the class methods fixes equality but seems to introduce conflicting ideas about how to set options on attributes. Can you provide some guidance?