Class: Coruro::MailcatcherAdapter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/coruro/mailcatcher_adapter.rb', line 11

def config
  @config
end

#runnerObject

Returns the value of attribute runner.



11
12
13
# File 'lib/coruro/mailcatcher_adapter.rb', line 11

def runner
  @runner
end

#timeoutObject

Returns the value of attribute timeout.



11
12
13
# File 'lib/coruro/mailcatcher_adapter.rb', line 11

def timeout
  @timeout
end

Instance Method Details

#allObject



20
21
22
# File 'lib/coruro/mailcatcher_adapter.rb', line 20

def all
  messages
end

#match?(query, value) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

#startObject



48
49
50
# File 'lib/coruro/mailcatcher_adapter.rb', line 48

def start
  runner.start(config)
end

#up?Boolean

Returns:

  • (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 = messages.select do |message|
      match?(to, message[:recipients]) ||
      match?(from, message[:sender]) ||
      match?(subject, message[:subject])
    end.map(&method(:find_by))
  end
  result
end