aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/railtie.rb
blob: 43a49360131ff72e8b20caa7a6b07c5f9681e366 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "action_mailer"
require "rails"

module ActionMailer
  class Railtie < Rails::Railtie
    config.action_mailer = ActiveSupport::OrderedOptions.new

    require "action_mailer/railties/log_subscriber"
    log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new

    initializer "action_mailer.logger" do
      ActiveSupport.on_load(:action_mailer) { self.logger ||= Rails.logger }
    end

    initializer "action_mailer.set_configs" do |app|
      paths = app.config.paths
      am = app.config.action_mailer

      am.assets_dir      ||= paths.public.to_a.first
      am.javascripts_dir ||= paths.public.javascripts.to_a.first
      am.stylesheets_dir ||= paths.public.stylesheets.to_a.first

      ActiveSupport.on_load(:action_mailer) do
        self.config.merge!(am)

        include app.routes.url_helpers

        app.config.action_mailer.each do |k,v|
          send "#{k}=", v
        end
      end
    end
  end
end