solnic / virtus

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

Unable to globally set attribute options #155

Closed aptinio closed 10 years ago

solnic commented 11 years ago

Oh riding on the edge? Nice, thanks for catching this. I will fix it prior 1.0.0.beta release.

aptinio commented 11 years ago

You're welcome! Is there a reason attributes aren't lazy by default?

solnic commented 11 years ago

@aptinio a bunch of people reported they couldn't use virtus bkz lazy evaluation of defaults made virtus too slow for their usecases; hence the change

aptinio commented 11 years ago

Oh, I see. I think I'll have to consider using lazy evaluation where necessary, instead of globally enabling it. Thanks again!

solnic commented 11 years ago

@aptinio I think there can be 2 reasons why you might want lazy evaluation of defaults: 1) default value depends on some other attribute value 2) default value is "heavy" and you not always need to access it (which is a smell anyway)

aptinio commented 11 years ago

In my case, it was reason no. 1. I had several attributes whose default values depend on other attributes. A lot of my tests failed after I pointed my Gemfile to virtus master. :-)

solnic commented 11 years ago

In most of the cases you want :lazy => false. Lemme know if you could make your tests pass. And thanks for trying out master :smile:

aptinio commented 11 years ago

I was able to make my tests pass by adding :lazy => true to the attributes that needed to be lazy. I thought it would be nice to just enable it globally. That's how I caught this issue. But, as pointed out, doing so isn't such a great idea.

solnic commented 10 years ago

This is fixed in master.