Closed aptinio closed 10 years ago
You're welcome! Is there a reason attributes aren't lazy by default?
@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
Oh, I see. I think I'll have to consider using lazy evaluation where necessary, instead of globally enabling it. Thanks again!
@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)
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. :-)
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:
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.
This is fixed in master.
Oh riding on the edge? Nice, thanks for catching this. I will fix it prior 1.0.0.beta release.