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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Da6e8a55a008ddb281d34b995090c536?d=identicon&s=25 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
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 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
Da6e8a55a008ddb281d34b995090c536?d=identicon&s=25 Mendis,V,Venura,DMK R (Guest)
on 2009-12-18 17:29
(Received via mailing list)
That and also the numerous debugger statements!

Venura
This topic is locked and can not be replied to.