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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e972d5e9538e44b78c6c54d0d394bdea0cb13c3438606d46161e738f7280815
4
- data.tar.gz: 0c757e7cd8cd4d66e63ba5a3d3c80bc3d395ed448f3755528c519995a6ba7b4e
3
+ metadata.gz: d1636eb84b5cd3b15f89f82c44c29a6b37bc5fc1ee162bbcb315e5d203f33d96
4
+ data.tar.gz: 3561bdf90cd90d3e6f17b3cab0bc4663e5123b516124f4a855834a7506bbf7f2
5
5
  SHA512:
6
- metadata.gz: ee53e053db2fa3eee837b455ccf16a987cacb642b619b19f7e8aee1a7e5de991fdc7dd20d8b2a4c7a10c0865b5e1f80e6f8d2c43a100aed696d2a9863a86db75
7
- data.tar.gz: 4c8c8567364f9c3fff19efbd22e97c46cf01778cffb1bc16852be7e277e34bde945d3a97637576ad73450796825dfac79e63fbd38e615cc501b5343e0a2291b6
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
- def initialize(timeout:)
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
- extend Forwardable
38
- def_delegators :runner, :up?, :start, :stop
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("http://127.0.0.1:1080/messages")), symbolize_names: true)
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("http://127.0.0.1:1080/messages/#{message_id}.eml"))
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('http://127.0.0.1:1080'))
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
@@ -1,3 +1,3 @@
1
1
  class Coruro
2
- VERSION="0.1.0"
2
+ VERSION="0.2.0"
3
3
  end
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.1.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-14 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail