class ActionMailbox::Router
Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when an inbound_email is received.
Attributes
routes[R]
Public Class Methods
new()
click to toggle source
# File lib/action_mailbox/router.rb, line 9 def initialize @routes = [] end
Public Instance Methods
add_route(address, to:)
click to toggle source
# File lib/action_mailbox/router.rb, line 19 def add_route(address, to:) routes.append Route.new(address, to: to) end
add_routes(routes)
click to toggle source
# File lib/action_mailbox/router.rb, line 13 def add_routes(routes) routes.each do |(address, mailbox_name)| add_route address, to: mailbox_name end end
route(inbound_email)
click to toggle source
# File lib/action_mailbox/router.rb, line 23 def route(inbound_email) if mailbox = match_to_mailbox(inbound_email) mailbox.receive(inbound_email) else inbound_email.bounced! raise RoutingError end end
Private Instance Methods
match_to_mailbox(inbound_email)
click to toggle source
# File lib/action_mailbox/router.rb, line 36 def match_to_mailbox(inbound_email) routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class) end