Action Mailbox Router

Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when an inbound_email is received.

Namespace

Class

Methods

Class Public methods

new()

📝 Source code
# File actionmailbox/lib/action_mailbox/router.rb, line 11
def initialize
  @routes = []
end
🔎 See on GitHub

Instance Public methods

add_route(address, to:)

📝 Source code
# File actionmailbox/lib/action_mailbox/router.rb, line 21
def add_route(address, to:)
  routes.append Route.new(address, to: to)
end
🔎 See on GitHub

add_routes(routes)

📝 Source code
# File actionmailbox/lib/action_mailbox/router.rb, line 15
def add_routes(routes)
  routes.each do |(address, mailbox_name)|
    add_route address, to: mailbox_name
  end
end
🔎 See on GitHub

mailbox_for(inbound_email)

📝 Source code
# File actionmailbox/lib/action_mailbox/router.rb, line 35
def mailbox_for(inbound_email)
  routes.detect { |route| route.match?(inbound_email) }&.mailbox_class
end
🔎 See on GitHub

route(inbound_email)

📝 Source code
# File actionmailbox/lib/action_mailbox/router.rb, line 25
def route(inbound_email)
  if mailbox = mailbox_for(inbound_email)
    mailbox.receive(inbound_email)
  else
    inbound_email.bounced!

    raise RoutingError
  end
end
🔎 See on GitHub

Definition files