I would like to include module in my Application Controller based on instance variable.
I’ve got something like this right now:
class ApplicationController
before_filter :include_module
def include_module
@@site = "foo"
class_eval{ include @@site.classify.constantize::Bar }
end
end
However, I would like to make this snippet thread safe. Is it possible? What I would like to achieve, is on each request load module, which name depends on some variable.
AFAIK Rails is thread safe and on MRI will be single threaded. However context matters. Are you running MRI or JRuby? I suggest you read through the following 3 once
http://m.onkey.org/thread-safety-for-your-rails
http://yehudakatz.com/2010/08/14/threads-in-ruby-enough-already/
http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html
EDIT: If your rails application is single threaded then your variables are thread safe. I should have added that before. In that context Rails is thread safe.