How to add a initialize method when rails app starts?

I know the Rails::Initializer class process the initialization for apps.
But
i found the method is under the protection. That is,

Rails::Initializer.run do |config|
end

when i invoke the run method, it then do process method which is the
actually initializing method.

I want to know how can i extend the method without changing
railties/lib/initializer.rb, in other words, how to extend it?

My requirement is to initialize ActionMailer::Base.smtp_settings. Though
there’s a built-in way to do it, i prefer the way performed as
database.yml,
which can put development, production and test environment all in a
file.

For example:

development:
server: 127.0.0.1
port: 25
domain: localhost

production:
server: 127.0.0.1
port: 25
domain: localhost

Recently, I use this way.

module Rails
class Initializer
def initialize_smtp
if configuration.frameworks.include?(:action_mailer) && RAILS_ENV
!=
‘test’
ActionMailer::Base.smtp_settings =
(configuration.smtp_configuration[RAILS_ENV]
|| {}).symbolize_keys
end
end
end

class Configuration
attr_accessor :smtp_configuration_file

def smtp_configuration
  self.smtp_configuration_file ||= default_smtp_configuration_file
  YAML::load(ERB.new(IO.read(smtp_configuration_file)).result)
end

private
def default_smtp_configuration_file
  File.join("#{RAILS_ROOT}", "config", "mailer.yml")
end

end
end

But following this, I only can initialize the mail system after the
initialization, as:

initializer = Rails::Initializer.run do |config|
end
initializer.initialize_smtp

It works, but not perfect really.

Does this a way to directly do the work when rails initialize itself?
Thank
you for any advice.

Does anybody have any advice?

Or i have to rewrite process method to fit the requirement.

How about solving it with “after_initialize” callback?
http://pastie.caboo.se/95439