Convention for using initializers end environments in engine

Hi Guys,

First of all great job with an extremely useful plugin infrastructure.

Ive been looking at migrating part of some existing code into an engine
within rails 2.3. Essentially trying to modularize some code. We have
different config for different environments and also may end up using
initializers. So far I have managed to get it to work by replicating the
same directory structure in the main rails app and including the
following code in the init.rb file in the plugin.

require ‘ruby-debug’

engine_directory = File.expand_path(File.join(File.dirname(FILE)))

config.after_initialize do

Dir[File.join(engine_directory,
“config/initializers/**/*.rb”)].sort.each do |engine_initializer|

initializer.require_or_load(engine_initializer)

end

engine_environment_path="#{engine_directory}/config/environments/#{confi
g.environment}.rb"

constants = self.class.constants

eval(IO.read(engine_environment_path), binding,
engine_environment_path)

(self.class.constants - constants).each do |const|

Object.const_set(const, self.class.const_get(const))

end

end

Everything seems to work but was wondering what the best
practice/convention was for doing this.

Thanks,

Venura

require ‘ruby-debug’

I assume you’ll take that out in production :slight_smile:
-r

That and also the numerous debugger statements!

Venura