W3cubDocs

/Ruby on Rails 6.0

class ActionMailbox::Router::Route

Parent:
Object

Encapsulates a route, which can then be matched against an inbound_email and provide a lookup of the matching mailbox class. See examples for the different route addresses and how to use them in the ActionMailbox::Base documentation.

Attributes

address[R]
mailbox_name[R]

Public Class Methods

new(address, to:) Show source
# File actionmailbox/lib/action_mailbox/router/route.rb, line 10
def initialize(address, to:)
  @address, @mailbox_name = address, to

  ensure_valid_address
end

Public Instance Methods

mailbox_class() Show source
# File actionmailbox/lib/action_mailbox/router/route.rb, line 31
def mailbox_class
  "#{mailbox_name.to_s.camelize}Mailbox".constantize
end
match?(inbound_email) Show source
# File actionmailbox/lib/action_mailbox/router/route.rb, line 16
def match?(inbound_email)
  case address
  when :all
    true
  when String
    inbound_email.mail.recipients.any? { |recipient| address.casecmp?(recipient) }
  when Regexp
    inbound_email.mail.recipients.any? { |recipient| address.match?(recipient) }
  when Proc
    address.call(inbound_email)
  else
    address.match?(inbound_email)
  end
end

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