ivory_tower 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: bd1f4d0e215ca1b4f98b68e0f3420b5bd02c3472
4
- data.tar.gz: dc9b3dce1535033b7dfb2d605337693d0086e3b5
3
+ metadata.gz: 93bbc845eefce4a6323c6069a6ee35538fce5446
4
+ data.tar.gz: c814fa6092da33bf715d9bfdfd3cadb896a07046
5
5
  SHA512:
6
- metadata.gz: 91ee17b56c2f4036a8598a426787bd794d43a4d037d9f1637bb6416ec31fa9075b06efee2e2a216b666acb34f67e05a9932e99e21cd0586573832cb50ef685b2
7
- data.tar.gz: e529257a9acae03ef40b01c0c98328052a2161469e44006d07592fb40bae7f3fcef1465bca8e9b47c425155443251ff4af7f928213e399c21959c416e2f58a14
6
+ metadata.gz: 64b8330157d5364488f37f607418cfef2f48475e2eeff226d736ae7aa31752c6245294fdcba0f0655c545ec6c6f1c0e5bcde5b8861d513ba23200adb2cf3f011
7
+ data.tar.gz: 63040860e6646eacbfb5685da92cb284d405c702fb09b9b6dc1d9d0da04afea37f8a340d7a367731e4a1f6f634cf278dbea0c3bb0d096dc6fa5fb810284b902f
data/ivory_tower.gemspec CHANGED
@@ -16,13 +16,13 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ["lib", "spec/support"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "guard-rspec"
25
- spec.add_development_dependency "pry-byebug"
26
25
 
27
26
  spec.add_dependency "bunny"
27
+ spec.add_dependency "hashie"
28
28
  end
data/lib/ivory_tower.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "ivory_tower/version"
2
2
  require "bunny"
3
- require 'pry-byebug'
3
+ require "hashie"
4
4
 
5
5
  module IvoryTower
6
6
  require "ivory_tower/bunny_factory"
@@ -1,13 +1,11 @@
1
1
  module IvoryTower::Consumer
2
2
  include IvoryTower::Queueable
3
3
 
4
- def run
4
+ def run(options = nil)
5
+ queue.subscribe_options = options if options
6
+
5
7
  queue.consume do |message|
6
8
  consume(message)
7
9
  end
8
10
  end
9
-
10
- def stop
11
- queue.close
12
- end
13
11
  end
@@ -8,12 +8,12 @@ class IvoryTower::Queue
8
8
 
9
9
  def consume(&block)
10
10
  bunny_queue.subscribe subscribe_options do |delivery_info, properties, body|
11
- message = JSON.parse body
11
+ message = Hashie::Mash.new(JSON.parse(body))
12
12
  block.call(message)
13
13
  channel.ack delivery_info.delivery_tag
14
14
  end
15
15
  ensure
16
- close
16
+ close_connection if subscribe_options[:block]
17
17
  end
18
18
 
19
19
  def produce(message)
@@ -24,20 +24,24 @@ class IvoryTower::Queue
24
24
  bunny_queue.message_count
25
25
  end
26
26
 
27
- def empty!
28
- bunny_queue.purge
27
+ def subscribe_options=(changes)
28
+ subscribe_options.merge!(changes)
29
29
  end
30
30
 
31
- def close
32
- unless [:closed, :closing].include? channel.connection.status
33
- channel.connection.close
34
- end
31
+ def empty!
32
+ bunny_queue.purge
35
33
  end
36
34
 
37
35
  private
38
36
 
39
37
  def subscribe_options
40
- {manual_ack: true, block: true}
38
+ @subscribe_options ||= {manual_ack: true, block: true}
39
+ end
40
+
41
+ def close_connection
42
+ unless channel.connection.status == :closed
43
+ channel.connection.close
44
+ end
41
45
  end
42
46
 
43
47
  def bunny_queue
@@ -1,3 +1,3 @@
1
1
  module IvoryTower
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -16,8 +16,7 @@ end
16
16
 
17
17
  describe 'Sending a message' do
18
18
  before :each do
19
- allow_any_instance_of(IvoryTower::Queue).to receive(:subscribe_options).and_return(manual_ack: true, block: false)
20
- allow_any_instance_of(IvoryTower::Queue).to receive(:close)
19
+ allow_any_instance_of(IvoryTower::Queue).to receive(:close_connection)
21
20
  end
22
21
 
23
22
  after :each do
@@ -35,7 +34,7 @@ describe 'Sending a message' do
35
34
  end
36
35
 
37
36
  it 'changes global through the queue' do
38
- AdditionConsumer.new.run
37
+ AdditionConsumer.new.run({block: false})
39
38
 
40
39
  p = AdditionProducer.new
41
40
  p.produce(addends: [1,3])
@@ -44,16 +43,3 @@ describe 'Sending a message' do
44
43
  expect($addition_value).to eq 4
45
44
  end
46
45
  end
47
-
48
- describe 'running the consumer' do
49
- # is this necessary? won't the ensure block catch this?
50
- it 'answers to stop' do
51
- consumer = AdditionConsumer.new
52
- t = Thread.new do
53
- consumer.run
54
- end
55
- connection = consumer.send(:queue).send(:channel).connection
56
- expect(connection).to receive(:close).and_call_original
57
- consumer.stop
58
- end
59
- end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
  require 'ivory_tower'
3
3
 
4
- FakeQueue = Struct.new(:channel, :close)
4
+ FakeQueue = Struct.new(:channel)
5
5
  FakeChannel = Struct.new(:connection)
6
6
  FakeConnection = Struct.new(:status, :close)
7
7
 
8
8
  def mock_queue
9
- FakeQueue.new(FakeChannel.new(FakeConnection.new(:open, nil)), nil)
9
+ FakeQueue.new(FakeChannel.new(FakeConnection.new(:open, nil)))
10
10
  end
11
11
 
12
12
  RSpec.configure do |config|
@@ -0,0 +1,8 @@
1
+ class IvoryTowerTestHelper
2
+ def self.setup_queue(name, &block)
3
+ queue = IvoryTower::Queue.new name
4
+ queue.empty!
5
+ block.call
6
+ queue.send(:channel).connection.close
7
+ end
8
+ end
@@ -24,16 +24,4 @@ describe IvoryTower::Consumer do
24
24
  expect($multiply_result).to eq 8
25
25
  end
26
26
  end
27
-
28
- describe "#stop" do
29
- it "closes the connection" do
30
- mocked = mock_queue
31
- expect(IvoryTower::Queue).to receive(:new).with("Multiply").and_return(mocked)
32
-
33
- mult = MultiplyConsumer.new
34
-
35
- expect(mocked).to receive(:close)
36
- mult.stop
37
- end
38
- end
39
27
  end
@@ -28,12 +28,4 @@ describe IvoryTower::Queue do
28
28
  queue.produce(message)
29
29
  end
30
30
  end
31
-
32
- describe "#close" do
33
- it "closes the connection" do
34
- queue = IvoryTower::Queue.new "Modulus"
35
- expect(stub_queue.channel.connection).to receive(:close)
36
- queue.close
37
- end
38
- end
39
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ivory_tower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ecuageo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-14 00:00:00.000000000 Z
12
+ date: 2014-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -68,13 +68,13 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: pry-byebug
71
+ name: bunny
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
- type: :development
77
+ type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: bunny
85
+ name: hashie
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - '>='
@@ -121,6 +121,7 @@ files:
121
121
  - lib/ivory_tower/version.rb
122
122
  - spec/integration/sending_a_message_spec.rb
123
123
  - spec/spec_helper.rb
124
+ - spec/support/ivory_tower_test_helper.rb
124
125
  - spec/unit/bunny_factory_spec.rb
125
126
  - spec/unit/consumer_spec.rb
126
127
  - spec/unit/producer_spec.rb
@@ -133,6 +134,7 @@ post_install_message:
133
134
  rdoc_options: []
134
135
  require_paths:
135
136
  - lib
137
+ - spec/support
136
138
  required_ruby_version: !ruby/object:Gem::Requirement
137
139
  requirements:
138
140
  - - '>='
@@ -152,6 +154,7 @@ summary: rabbitmq abstractions
152
154
  test_files:
153
155
  - spec/integration/sending_a_message_spec.rb
154
156
  - spec/spec_helper.rb
157
+ - spec/support/ivory_tower_test_helper.rb
155
158
  - spec/unit/bunny_factory_spec.rb
156
159
  - spec/unit/consumer_spec.rb
157
160
  - spec/unit/producer_spec.rb