diff options
author | George Claghorn <george@basecamp.com> | 2018-12-26 16:18:42 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-12-26 16:18:42 -0500 |
commit | 6c168aaffb37c62dee6c895a22e240e5552be669 (patch) | |
tree | b081b79a1088d9bc2bad0ee9f85fd4d7e5cc3638 /actionmailbox/lib/action_mailbox/router.rb | |
parent | 11a8ba12723c919397c8ccc0b4cf2e9f50da99ed (diff) | |
download | rails-6c168aaffb37c62dee6c895a22e240e5552be669.tar.gz rails-6c168aaffb37c62dee6c895a22e240e5552be669.tar.bz2 rails-6c168aaffb37c62dee6c895a22e240e5552be669.zip |
Nest Action Mailbox classes in the API docs
Diffstat (limited to 'actionmailbox/lib/action_mailbox/router.rb')
-rw-r--r-- | actionmailbox/lib/action_mailbox/router.rb | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/actionmailbox/lib/action_mailbox/router.rb b/actionmailbox/lib/action_mailbox/router.rb index 0f041a8389..71370e409d 100644 --- a/actionmailbox/lib/action_mailbox/router.rb +++ b/actionmailbox/lib/action_mailbox/router.rb @@ -1,40 +1,42 @@ # frozen_string_literal: true -# Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when -# an inbound_email is received. -class ActionMailbox::Router - class RoutingError < StandardError; end - - def initialize - @routes = [] - end +module ActionMailbox + # Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when + # an inbound_email is received. + class Router + class RoutingError < StandardError; end + + def initialize + @routes = [] + end - def add_routes(routes) - routes.each do |(address, mailbox_name)| - add_route address, to: mailbox_name + def add_routes(routes) + routes.each do |(address, mailbox_name)| + add_route address, to: mailbox_name + end end - end - def add_route(address, to:) - routes.append Route.new(address, to: to) - end + def add_route(address, to:) + routes.append Route.new(address, to: to) + end - def route(inbound_email) - if mailbox = match_to_mailbox(inbound_email) - mailbox.receive(inbound_email) - else - inbound_email.bounced! + def route(inbound_email) + if mailbox = match_to_mailbox(inbound_email) + mailbox.receive(inbound_email) + else + inbound_email.bounced! - raise RoutingError + raise RoutingError + end end - end - private - attr_reader :routes + private + attr_reader :routes - def match_to_mailbox(inbound_email) - routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class) - end + def match_to_mailbox(inbound_email) + routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class) + end + end end require "action_mailbox/router/route" |