Class: ActionMailbox::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mailbox/router.rb

Overview

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

Defined Under Namespace

Classes: Route, RoutingError

Instance Method Summary collapse

Constructor Details

#initializeRouter



6
7
8
# File 'lib/action_mailbox/router.rb', line 6

def initialize
  @routes = []
end

Instance Method Details

#add_route(address, to:) ⇒ Object



16
17
18
# File 'lib/action_mailbox/router.rb', line 16

def add_route(address, to:)
  routes.append Route.new(address, to: to)
end

#add_routes(routes) ⇒ Object



10
11
12
13
14
# File 'lib/action_mailbox/router.rb', line 10

def add_routes(routes)
  routes.each do |(address, mailbox_name)|
    add_route address, to: mailbox_name
  end
end

#route(inbound_email) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/action_mailbox/router.rb', line 20

def route(inbound_email)
  if mailbox = match_to_mailbox(inbound_email)
    mailbox.receive(inbound_email)
  else
    inbound_email.bounced!

    raise RoutingError
  end
end