Class: Coruro::MailcatcherAdapter
- Inherits:
-
Object
- Object
- Coruro::MailcatcherAdapter
- Extended by:
- Forwardable
- Defined in:
- lib/coruro/mailcatcher_adapter.rb
Overview
Translates between Curoro and Mailcatcher’s API
Defined Under Namespace
Classes: Configuration, Runner
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(timeout:, config:) ⇒ MailcatcherAdapter
constructor
A new instance of MailcatcherAdapter.
- #match?(query, value) ⇒ Boolean
- #start ⇒ Object
- #up? ⇒ Boolean
- #where(to: nil, from: nil, subject: nil) ⇒ Object
Constructor Details
#initialize(timeout:, config:) ⇒ MailcatcherAdapter
Returns a new instance of MailcatcherAdapter.
15 16 17 18 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 15 def initialize(timeout:, config:) self.timeout = timeout self.config = Configuration.new(config) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 11 def config @config end |
#runner ⇒ Object
Returns the value of attribute runner.
11 12 13 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 11 def runner @runner end |
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 11 def timeout @timeout end |
Instance Method Details
#all ⇒ Object
20 21 22 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 20 def all end |
#match?(query, value) ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 36 def match?(query, value) return false if query.nil? return value.any? { |child| match?(query, child) } if value.respond_to?(:any?) return query.match?(value) if query.respond_to?(:match?) return !query.match(value).nil? if query.respond_to?(:match) raise ArgumentError, "Query #{query} must respond to `match?` or Value #{value} must respond to `any?`" end |
#start ⇒ Object
48 49 50 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 48 def start runner.start(config) end |
#up? ⇒ Boolean
44 45 46 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 44 def up? runner.up?(config) end |
#where(to: nil, from: nil, subject: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coruro/mailcatcher_adapter.rb', line 24 def where(to: nil, from: nil, subject: nil) result = []; start_time = Time.now.to_f while (result.empty? && (Time.now.to_f - start_time) <= timeout) result = .select do || match?(to, [:recipients]) || match?(from, [:sender]) || match?(subject, [:subject]) end.map(&method(:find_by)) end result end |