Forum: Rails Engines convention for using initializers end environments in engine

Posted by unknown (Guest)
on 2009-12-18 12:56
(Received via mailing list)
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
Posted by Roger Pack (rogerdpack)
on 2009-12-18 16:46
(Received via mailing list)
> require 'ruby-debug'

I assume you'll take that out in production :)
-r
Posted by Mendis,V,Venura,DMK R (Guest)
on 2009-12-18 17:29
(Received via mailing list)
That and also the numerous debugger statements!

Venura
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.