rusty geldmacher
2006-Mar-10 03:44 UTC
[Rails] Changes to class caching between Rails 0.14.3 and 1.0?
Hi all,
We''re having a rather unique problem with class caching. We are
implementing the strategy pattern in the following manner:
1. Set an accessor for the class, let''s call it :strategy
class Widget
cattr_accessor :strategy
end
2. In environment.rb, we instantiate an object that implements the
strategy and use the accessor to set it for the class
strat = MyStrategy.new
Widget.strategy = strat
3. In the regular flow of the application, that strategy gets accessed
so it can affect some behavior:
...
Widget.strategy.do(:foo)
...
OK, now in development mode, class caching is off. In Rails 0.14.3 this
didn''t seem to matter -- the class variable stayed set. But now
mysteriously in Rails 1.0 I will get an exception when trying to call
.do() on nil... ie, Widget.strategy becomes nil at some point. I''m
assuming the class gets unloaded and then reloaded without :strategy
ever getting set again. That''s likely because the environment never got
to set up the class variable again.
So, in 0.14.3, did the environment get evaluated again? Or did the class
never really get unloaded?
Does anyone know a way I can avoid this problem? Is there a way to
control class caching on a per-class basis? Looking at "module
Dependencies" makes me believe there is not.
Thanks for any help,
rusty
--
Posted via http://www.ruby-forum.com/.
Rick Olson
2006-Mar-10 03:56 UTC
[Rails] Changes to class caching between Rails 0.14.3 and 1.0?
> Does anyone know a way I can avoid this problem? Is there a way to > control class caching on a per-class basis? Looking at "module > Dependencies" makes me believe there is not. > > Thanks for any help, > rustyTry this on edge rails... class Widget < AR::Base def self.reloadable?() false; end end -- Rick Olson http://techno-weenie.net
Rick Olson
2006-Mar-10 03:57 UTC
[Rails] Changes to class caching between Rails 0.14.3 and 1.0?
> Try this on edge rails... > > class Widget < AR::Base > def self.reloadable?() false; end > end >Doh, sorry, I read that as 1.1.
rusty geldmacher
2006-Mar-10 14:59 UTC
[Rails] Re: Changes to class caching between Rails 0.14.3 and 1.0?
Rick Olson wrote:>> Try this on edge rails... >> >> class Widget < AR::Base >> def self.reloadable?() false; end >> end >> > > Doh, sorry, I read that as 1.1.Hi Rick, Thanks for the reply! Are you saying that this problem can be addressed if I use Rails 1.1? Thanks, rusty -- Posted via http://www.ruby-forum.com/.