Class: ActionMailbox::Router::Route
- Defined in:
- actionmailbox/lib/action_mailbox/router/route.rb
Overview
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.
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#mailbox_name ⇒ Object
readonly
Returns the value of attribute mailbox_name.
Instance Method Summary collapse
-
#initialize(address, to:) ⇒ Route
constructor
A new instance of Route.
- #mailbox_class ⇒ Object
- #match?(inbound_email) ⇒ Boolean
Constructor Details
#initialize(address, to:) ⇒ Route
Returns a new instance of Route.
10 11 12 13 14 |
# File 'actionmailbox/lib/action_mailbox/router/route.rb', line 10 def initialize(address, to:) @address, @mailbox_name = address, to ensure_valid_address end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address
8 9 10 |
# File 'actionmailbox/lib/action_mailbox/router/route.rb', line 8 def address @address end |
#mailbox_name ⇒ Object (readonly)
Returns the value of attribute mailbox_name
8 9 10 |
# File 'actionmailbox/lib/action_mailbox/router/route.rb', line 8 def mailbox_name @mailbox_name end |
Instance Method Details
#mailbox_class ⇒ Object
31 32 33 |
# File 'actionmailbox/lib/action_mailbox/router/route.rb', line 31 def mailbox_class "#{mailbox_name.to_s.camelize}Mailbox".constantize end |
#match?(inbound_email) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |