Class: Coruro::MailcatcherAdapter::Runner

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/coruro/mailcatcher_adapter.rb

Overview

Allows for launching and terminating mailcatcher programmaticaly

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stderrObject

Returns the value of attribute stderr.



74
75
76
# File 'lib/coruro/mailcatcher_adapter.rb', line 74

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



74
75
76
# File 'lib/coruro/mailcatcher_adapter.rb', line 74

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



74
75
76
# File 'lib/coruro/mailcatcher_adapter.rb', line 74

def stdout
  @stdout
end

#threadObject

Returns the value of attribute thread.



74
75
76
# File 'lib/coruro/mailcatcher_adapter.rb', line 74

def thread
  @thread
end

Instance Method Details

#start(config) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/coruro/mailcatcher_adapter.rb', line 77

def start(config)
  return if up?(config)
  new_env = Unbundle.all(ENV)
  self.stdin, self.stdout, self.stderr, self.thread =
    Open3.popen3(new_env, 'mailcatcher -f --ip=0.0.0.0', { unsetenv_others:true })

  debug_stream(:stdout, config: config)
  debug_stream(:stderr, config: config)
end

#stopObject



94
95
96
97
98
99
100
101
# File 'lib/coruro/mailcatcher_adapter.rb', line 94

def stop

  return unless self.thread
  streams.each do |(_, stream)|
    stream.close
  end
  `kill -9 #{ thread[:pid] }`
end

#up?(config) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/coruro/mailcatcher_adapter.rb', line 87

def up?(config)
  response = Net::HTTP.get_response(URI("#{config.http_root}"))
  response.is_a?(Net::HTTPSuccess)
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL => _
  false
end