W3cubDocs

/Ruby on Rails 7.0

class ActionMailbox::Router

Parent:
Object

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

Public Class Methods

new() Show source
# File actionmailbox/lib/action_mailbox/router.rb, line 9
def initialize
  @routes = []
end

Public Instance Methods

add_route(address, to:) Show source
# File actionmailbox/lib/action_mailbox/router.rb, line 19
def add_route(address, to:)
  routes.append Route.new(address, to: to)
end
add_routes(routes) Show source
# File actionmailbox/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
mailbox_for(inbound_email) Show source
# File actionmailbox/lib/action_mailbox/router.rb, line 33
def mailbox_for(inbound_email)
  routes.detect { |route| route.match?(inbound_email) }&.mailbox_class
end
route(inbound_email) Show source
# File actionmailbox/lib/action_mailbox/router.rb, line 23
def route(inbound_email)
  if mailbox = mailbox_for(inbound_email)
    mailbox.receive(inbound_email)
  else
    inbound_email.bounced!

    raise RoutingError
  end
end

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.