coruro-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coruro/mailcatcher_adapter.rb +32 -11
- data/lib/coruro/version.rb +1 -1
- data/lib/coruro.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1636eb84b5cd3b15f89f82c44c29a6b37bc5fc1ee162bbcb315e5d203f33d96
|
4
|
+
data.tar.gz: 3561bdf90cd90d3e6f17b3cab0bc4663e5123b516124f4a855834a7506bbf7f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2011440906600e90104b50263b5394b6eb9be4d76dbc0b88966ab84afc7cedfb454cc377e6326fe5ca7be1dc220af3334216b786a3edf1a7ea286b3854eb4e20
|
7
|
+
data.tar.gz: 064f4497aa06561f9b3b7d078e743435e0105312dbb5e64afe91207dcd81d000c99be8a6e414bde6a083ea7f3fff9b973476dc0294ea64b6f582346d58f64b2d
|
@@ -4,11 +4,25 @@ require 'open3'
|
|
4
4
|
require 'singleton'
|
5
5
|
|
6
6
|
class Coruro
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :config
|
9
|
+
def initialize(config)
|
10
|
+
self.config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def http_root
|
14
|
+
self.config[:http_root] || 'http://localhost:1080'
|
15
|
+
end
|
16
|
+
end
|
7
17
|
# Translates between Curoro and Mailcatcher's API
|
8
18
|
class MailcatcherAdapter
|
9
|
-
attr_accessor :runner, :timeout
|
10
|
-
|
19
|
+
attr_accessor :runner, :timeout, :config
|
20
|
+
extend Forwardable
|
21
|
+
def_delegators :runner, :stop
|
22
|
+
def_delegators :config, :http_root
|
23
|
+
def initialize(timeout:, config:)
|
11
24
|
self.timeout = timeout
|
25
|
+
self.config = Configuration.new(config)
|
12
26
|
end
|
13
27
|
|
14
28
|
def all
|
@@ -34,19 +48,25 @@ class Coruro
|
|
34
48
|
raise ArgumentError, "Query #{query} must respond to `match?` or Value #{value} must respond to `any?`"
|
35
49
|
end
|
36
50
|
|
37
|
-
|
38
|
-
|
51
|
+
|
52
|
+
def up?
|
53
|
+
runner.up?(config)
|
54
|
+
end
|
55
|
+
|
56
|
+
def start
|
57
|
+
runner.start(config)
|
58
|
+
end
|
39
59
|
|
40
60
|
def runner
|
41
61
|
@_runner ||= Runner.instance
|
42
62
|
end
|
43
63
|
|
44
64
|
private def messages
|
45
|
-
JSON.parse(Net::HTTP.get(URI("
|
65
|
+
JSON.parse(Net::HTTP.get(URI("#{http_root}/messages")), symbolize_names: true)
|
46
66
|
end
|
47
67
|
|
48
68
|
private def raw_message(message_id)
|
49
|
-
Net::HTTP.get(URI("
|
69
|
+
Net::HTTP.get(URI("#{http_root}/messages/#{message_id}.eml"))
|
50
70
|
end
|
51
71
|
|
52
72
|
|
@@ -59,16 +79,17 @@ class Coruro
|
|
59
79
|
# Allows for launching and terminating mailcatcher programmaticaly
|
60
80
|
class Runner
|
61
81
|
include Singleton
|
62
|
-
attr_accessor :stdin, :stdout, :stderr, :thread
|
82
|
+
attr_accessor :stdin, :stdout, :stderr, :thread, :config
|
83
|
+
|
63
84
|
|
64
|
-
def start
|
65
|
-
return if up?
|
85
|
+
def start(config)
|
86
|
+
return if up?(config)
|
66
87
|
self.stdin, self.stdout, self.stderr, self.thread =
|
67
88
|
Open3.popen3({ "PATH" => ENV['PATH'] }, 'mailcatcher -f', { unsetenv_others:true })
|
68
89
|
end
|
69
90
|
|
70
|
-
def up?
|
71
|
-
response = Net::HTTP.get_response(URI(
|
91
|
+
def up?(config)
|
92
|
+
response = Net::HTTP.get_response(URI("#{config.http_root}"))
|
72
93
|
response.is_a?(Net::HTTPSuccess)
|
73
94
|
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL => _
|
74
95
|
false
|
data/lib/coruro/version.rb
CHANGED
data/lib/coruro.rb
CHANGED
@@ -11,10 +11,10 @@ class Coruro
|
|
11
11
|
extend Forwardable
|
12
12
|
def_delegators :adapter, :all, :where, :stop
|
13
13
|
|
14
|
-
def initialize(adapter:, on_wait_tick: -> (count) { }, timeout: 0.1)
|
14
|
+
def initialize(adapter:, on_wait_tick: -> (count) { }, timeout: 0.1, adapter_config: {})
|
15
15
|
case adapter
|
16
16
|
when :mailcatcher
|
17
|
-
self.adapter = MailcatcherAdapter.new(timeout: timeout)
|
17
|
+
self.adapter = MailcatcherAdapter.new(timeout: timeout, config: adapter_config)
|
18
18
|
self.adapter.start
|
19
19
|
else
|
20
20
|
raise UnrecognizedAdapterError, adapter
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coruro-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zee Spencer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|