aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_mailroom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/action_mailroom')
-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)