aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 15:52:16 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 15:52:16 -0700
commitda697e84445f8f750b8a7d0fa916f429eda8aae4 (patch)
tree510ad1391fedcdc7a3433ef4af128007fa7fbfa0 /lib
parentee6d9545dd69a96ae30fdacf264db83fbaa1e4dd (diff)
downloadrails-da697e84445f8f750b8a7d0fa916f429eda8aae4.tar.gz
rails-da697e84445f8f750b8a7d0fa916f429eda8aae4.tar.bz2
rails-da697e84445f8f750b8a7d0fa916f429eda8aae4.zip
Attach a concrete router to the root mailbox and use it
Don't think this is how it's going to stay. Doesn't feel like the right place for it.
Diffstat (limited to 'lib')
-rw-r--r--lib/action_mailroom/mailbox.rb18
-rw-r--r--lib/action_mailroom/mailbox/routing.rb15
-rw-r--r--lib/action_mailroom/router.rb8
3 files changed, 29 insertions, 12 deletions
diff --git a/lib/action_mailroom/mailbox.rb b/lib/action_mailroom/mailbox.rb
index a2c097a42f..3518449794 100644
--- a/lib/action_mailroom/mailbox.rb
+++ b/lib/action_mailroom/mailbox.rb
@@ -1,21 +1,19 @@
require "active_support/rescuable"
+
require "action_mailroom/mailbox/callbacks"
+require "action_mailroom/mailbox/routing"
class ActionMailroom::Mailbox
- include ActiveSupport::Rescuable, Callbacks
+ include ActiveSupport::Rescuable
+ include Callbacks, Routing
- class << self
- def receive(inbound_email)
- new(inbound_email).perform_processing
- end
+ attr_reader :inbound_email
+ delegate :mail, to: :inbound_email
- def routing(routes)
- @router = ActionMailroom::Router.new(routes)
- end
+ def self.receive(inbound_email)
+ new(inbound_email).perform_processing
end
- attr_reader :inbound_email
- delegate :mail, to: :inbound_email
def initialize(inbound_email)
@inbound_email = inbound_email
diff --git a/lib/action_mailroom/mailbox/routing.rb b/lib/action_mailroom/mailbox/routing.rb
new file mode 100644
index 0000000000..9f082c8aa5
--- /dev/null
+++ b/lib/action_mailroom/mailbox/routing.rb
@@ -0,0 +1,15 @@
+module ActionMailroom::Mailbox::Routing
+ extend ActiveSupport::Concern
+
+ class_methods do
+ attr_reader :router
+
+ def routing(routes)
+ (@router ||= ActionMailroom::Router.new).add_routes(routes)
+ end
+
+ def route(inbound_email)
+ @router.route(inbound_email)
+ end
+ end
+end
diff --git a/lib/action_mailroom/router.rb b/lib/action_mailroom/router.rb
index 066d7163e4..bf0001f1ae 100644
--- a/lib/action_mailroom/router.rb
+++ b/lib/action_mailroom/router.rb
@@ -1,6 +1,10 @@
class ActionMailroom::Router
- def initialize(routes)
- @routes = routes
+ def initialize
+ @routes = {}
+ end
+
+ def add_routes(routes)
+ @routes.merge!(routes)
end
def route(inbound_email)