aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_mailbox/engine.rb
blob: cf438d8f243b871b2800f95c9ab0d2822f04e533 (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
require "rails/engine"

module ActionMailbox
  class Engine < Rails::Engine
    isolate_namespace ActionMailbox
    config.eager_load_namespaces << ActionMailbox

    config.action_mailbox = ActiveSupport::OrderedOptions.new
    config.action_mailbox.incinerate_after = 30.days

    initializer "action_mailbox.config" do
      config.after_initialize do |app|
        ActionMailbox.logger = app.config.action_mailbox.logger || Rails.logger
        ActionMailbox.incinerate_after = app.config.action_mailbox.incinerate_after || 30.days
      end
    end

    initializer "action_mailbox.ingress" do
      config.after_initialize do |app|
        if ActionMailbox.ingress = app.config.action_mailbox.ingress.presence
          config.to_prepare do
            if ingress_controller_class = "ActionMailbox::Ingresses::#{ActionMailbox.ingress.to_s.classify}::InboundEmailsController".safe_constantize
              ingress_controller_class.prepare
            end
          end
        end
      end
    end
  end
end