multiple_man 0.5.8 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14b664ec408ce39903e299ff4be21513e3925014
4
- data.tar.gz: 00b8579e4aeaa8e8697e5fa963646aef68757377
3
+ metadata.gz: 45d1f3a68bbb6908b822a5b57a3c176152851b57
4
+ data.tar.gz: bf316745d372637203f5a976f14e07c50fe9d213
5
5
  SHA512:
6
- metadata.gz: acaec63c148e65ea63833d342fe28f1de23c80d07074dbf413531860fd9fda3ff4a334a6500c23cd2181fd908abbc9c78c03af475f67e5e0e734d491c7c7149f
7
- data.tar.gz: f5620fc66f82bcb0708b8a564b472d1ac5ba98aa1742e0502b6e02b37629f3809dbe862f5809fa54945321fc03e87d0e54376f98bd18b8c9c6e814a981fe018a
6
+ metadata.gz: caba00db5b03de4f14b6e473e765bfc1096b5dd1a06f60fd84ec31a3692fafbce3aa3893fc75a97582767f4640787a3fff1b82b36d22d4e58c5cfa02af9044b4
7
+ data.tar.gz: e6b17cff6eb2fc1b90287969218fbf4b228dd59b499a1ed87787149997c6090dd64782af35d6526dd0bc8e3ac27b90822d83f450a8984507f48c0304f431e8e0
@@ -4,30 +4,18 @@ require 'active_support/core_ext/module'
4
4
 
5
5
  module MultipleMan
6
6
  class Connection
7
- @mutex = Mutex.new
8
-
9
- def self.connection
10
- @mutex.synchronize do
11
- @connection ||= begin
12
- connection = Bunny.new(MultipleMan.configuration.connection)
13
- MultipleMan.logger.debug "Connecting to #{MultipleMan.configuration.connection}"
14
- connection.start
15
- connection
16
- end
17
- end
18
- end
19
-
20
7
  def self.connect
21
- channel = connection.create_channel
22
- yield new(channel) if block_given?
8
+ connection = new
9
+ yield connection if block_given?
23
10
  ensure
24
- channel.close if channel
11
+ connection.close! if connection
25
12
  end
26
13
 
27
14
  attr_reader :topic
28
15
 
29
- def initialize(channel)
30
- self.channel = channel
16
+ def initialize
17
+ init_connection!
18
+ init_channel!
31
19
  self.topic = channel.topic(topic_name)
32
20
  end
33
21
 
@@ -35,11 +23,25 @@ module MultipleMan
35
23
  MultipleMan.configuration.topic_name
36
24
  end
37
25
 
26
+ def close!
27
+ channel.close if channel
28
+ connection.close if connection
29
+ end
30
+
38
31
  delegate :queue, to: :channel
39
32
 
40
33
  private
41
34
 
42
- attr_accessor :channel
35
+ def init_connection!
36
+ self.connection = Bunny.new(MultipleMan.configuration.connection)
37
+ connection.start
38
+ end
39
+
40
+ def init_channel!
41
+ self.channel = connection.create_channel
42
+ end
43
+
44
+ attr_accessor :channel, :connection
43
45
  attr_writer :topic
44
46
 
45
47
  end
@@ -1,3 +1,3 @@
1
1
  module MultipleMan
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
3
3
  end
@@ -3,19 +3,21 @@ require 'spec_helper'
3
3
  describe MultipleMan::Connection do
4
4
 
5
5
  let(:mock_bunny) { double(Bunny) }
6
- let(:mock_channel) { double(Bunny::Channel, close: nil) }
6
+ let(:mock_channel) { double(Bunny::Channel, topic: nil) }
7
7
 
8
8
  describe "connect" do
9
9
  it "should open a connection and a channel" do
10
10
  mock_bunny.should_receive(:start)
11
11
  Bunny.should_receive(:new).and_return(mock_bunny)
12
12
  mock_bunny.should_receive(:create_channel).once.and_return(mock_channel)
13
+ mock_bunny.should_receive(:close)
14
+ mock_channel.should_receive(:close)
13
15
 
14
16
  described_class.connect { }
15
17
  end
16
18
  end
17
19
 
18
- subject { described_class.new(mock_channel) }
20
+ subject { described_class.new }
19
21
 
20
22
  its(:topic_name) { should == MultipleMan.configuration.topic_name }
21
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiple_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler