diff options
author | George Claghorn <george@basecamp.com> | 2018-12-26 16:18:42 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-12-26 16:18:42 -0500 |
commit | 6c168aaffb37c62dee6c895a22e240e5552be669 (patch) | |
tree | b081b79a1088d9bc2bad0ee9f85fd4d7e5cc3638 /actionmailbox/lib/action_mailbox/router/route.rb | |
parent | 11a8ba12723c919397c8ccc0b4cf2e9f50da99ed (diff) | |
download | rails-6c168aaffb37c62dee6c895a22e240e5552be669.tar.gz rails-6c168aaffb37c62dee6c895a22e240e5552be669.tar.bz2 rails-6c168aaffb37c62dee6c895a22e240e5552be669.zip |
Nest Action Mailbox classes in the API docs
Diffstat (limited to 'actionmailbox/lib/action_mailbox/router/route.rb')
-rw-r--r-- | actionmailbox/lib/action_mailbox/router/route.rb | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/actionmailbox/lib/action_mailbox/router/route.rb b/actionmailbox/lib/action_mailbox/router/route.rb index adb9f94c1a..b681eb7ea8 100644 --- a/actionmailbox/lib/action_mailbox/router/route.rb +++ b/actionmailbox/lib/action_mailbox/router/route.rb @@ -1,40 +1,42 @@ # frozen_string_literal: true -# 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. -class ActionMailbox::Router::Route - attr_reader :address, :mailbox_name +module ActionMailbox + # 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. + class Router::Route + attr_reader :address, :mailbox_name - def initialize(address, to:) - @address, @mailbox_name = address, to + def initialize(address, to:) + @address, @mailbox_name = address, to - ensure_valid_address - end + ensure_valid_address + end - 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) + 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 - end - def mailbox_class - "#{mailbox_name.to_s.camelize}Mailbox".constantize - end + def mailbox_class + "#{mailbox_name.to_s.camelize}Mailbox".constantize + end - private - def ensure_valid_address - unless [ Symbol, String, Regexp, Proc ].any? { |klass| address.is_a?(klass) } || address.respond_to?(:match?) - raise ArgumentError, "Expected a Symbol, String, Regexp, Proc, or matchable, got #{address.inspect}" + private + def ensure_valid_address + unless [ Symbol, String, Regexp, Proc ].any? { |klass| address.is_a?(klass) } || address.respond_to?(:match?) + raise ArgumentError, "Expected a Symbol, String, Regexp, Proc, or matchable, got #{address.inspect}" + end end - end + end end |