Action Mailbox Router
Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when an inbound_email is received.
     
  
  
  
  
  
    
    Namespace
    
  
  
    
    Methods
    
      
        - A
- 
          
        
- M
- 
          
        
- N
- 
          
        
- R
- 
          
        
Class Public methods
      
        
        
      
    
      Instance Public methods
      
        
          
            
              add_route(address, to:)
            
            Link
          
          
            
              
            
          
          
          
          
            
            
              
              
                 Source: 
                
                  show
                
                 | 
                
                  on GitHub
                
              
              
                
def add_route(address, to:)
  routes.append Route.new(address, to: to)
end
               
             
            
           
        
        
          
            
              add_routes(routes)
            
            Link
          
          
            
              
            
          
          
          
          
            
            
              
              
                 Source: 
                
                  show
                
                 | 
                
                  on GitHub
                
              
              
                
def add_routes(routes)
  routes.each do |(address, mailbox_name)|
    add_route address, to: mailbox_name
  end
end
               
             
            
           
        
        
          
            
              mailbox_for(inbound_email)
            
            Link
          
          
            
              
            
          
          
          
          
            
            
              
              
                 Source: 
                
                  show
                
                 | 
                
                  on GitHub
                
              
              
                
def mailbox_for(inbound_email)
  routes.detect { |route| route.match?(inbound_email) }&.mailbox_class
end
               
             
            
           
        
        
          
            
              route(inbound_email)
            
            Link
          
          
            
              
            
          
          
          
          
            
            
              
              
                 Source: 
                
                  show
                
                 | 
                
                  on GitHub
                
              
              
                
def route(inbound_email)
  if mailbox = mailbox_for(inbound_email)
    mailbox.receive(inbound_email)
  else
    inbound_email.bounced!
    raise RoutingError
  end
end