1

I have a an initializer in my Rails 3.2 app that includes modules at startup based on a configuration file. It looks something like this:

Array(Settings.site.authentications).map(&:to_sym).each do |sym|
  AuthAuth.class_eval do
    include Object.const_get(sym)
  end
end

Array(Settings.site.authorizations).map(&:to_sym).each do |sym|
  AuthAuth.class_eval do
    include Object.const_get(sym)
  end
end

# This exception is never raised when I start the server.  So the includes 
# appear to be working correctly.
raise "method not found!" unless AuthAuth.new.respond_to? :dynamically_included_method

AuthAuth is used in my ApplicationController in a :before_filter to ensure that users are authenticated and authorized. It works fine and suites the requirement that I have a configurable way of setting authorization and authentication logic on a per-site basis.

I've noticed, however, that when I am running the server in development mode if I make a code change to any class in the application, AuthAuth reverts to it's default behavior without the included modules.

Is there an appropriate place to include this code other than an initialization file?

This is a relatively minor issue. It's easy enough to restart the development server after each code change, but I'm curious.

GSP
  • 3,763
  • 3
  • 32
  • 54

0 Answers0