solnic / virtus

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

Seemingly inconsistent attribute_set behavior #178

Closed bcobb closed 11 years ago

bcobb commented 11 years ago

I've written a few tests which demonstrate some unexpected (to me) behavior when including another Class's attribute_set. I'll refer to classes which include Virtus as Entities and to classes which include Virtus::ValueObject as Values.

N.B. I may well be abusing the fact that an AttributeSet is a module, and would appreciate a gentle course-correction if that is the case :grin:

What I've found is that it looks like it's possible to grab an attribute set from an Entity, include it in either a Value or another Entity, and build "on top" of the included attribute set. However, it is only half-possible to grab an attribute set from a Value and do the same. I say "half-possible" since the included attribute set's reader methods are included, but I am unable to set those attributes through the constructor.

If that's not comprehensible, the linked tests express it in code. The first test and the last test are the failure cases.

What's most puzzling to me is that this behavior seems to depend on the AttributeSet and not the class into which it is included.

solnic commented 11 years ago

For sharing attributes you can use Virtus::Module extension like explained here