bi-frost 0.1.3 → 0.1.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: e2c0c05d4f226f4592d8b654a36e2a324dcf0042
4
- data.tar.gz: 2a085487e7a616543e690d4d428d89087d1b750d
3
+ metadata.gz: 9bae9c137149abf5f29d00b38d46763ead852eec
4
+ data.tar.gz: 6dbd4e1370c6b62ce67bd7df6826b0a8d75e664b
5
5
  SHA512:
6
- metadata.gz: 89b9ae01ccb0f14d03d926494afa83491b98cbc597b796a1e8eb48e606acc92b8bc23648b16548a7df71803b16b5536ec285262fde25d1a09cee58aebb3cb8cf
7
- data.tar.gz: da58e3c72a1e34338089a4a253e56fe60871f5564538613379b6d510827a42682d8d51e8dca56b3742c556eeb1beed4aa3952a6eb479e8eb60dd8ffe274e5c94
6
+ metadata.gz: e07411b6991e054810097254fc39d2e5745ff2fccb2a75bdb0e9c4051c269feed887094c4e2eaef128a37d4978ba453c263da0c903e199163d6e4b7b1b0f3ea0
7
+ data.tar.gz: 105f3f014d5fb0d5444f03b6c258eb9fdc2e0cbaf65b97089b87167ddf0f728f9a78dda8dc7356736b043f1bc57d8f087e1eaec197cad6cd2339be00e9285962
data/lib/bifrost/bus.rb CHANGED
@@ -10,15 +10,41 @@ module Bifrost
10
10
  def initialize
11
11
  Azure.sb_namespace = ENV['AZURE_BUS_NAMESPACE']
12
12
  host = "https://#{Azure.sb_namespace}.servicebus.windows.net"
13
- signer = Azure::ServiceBus::Auth::SharedAccessSigner.new(ENV['AZURE_BUS_KEY_NAME'], ENV['AZURE_BUS_KEY_SECRET'])
13
+ signer = Azure::ServiceBus::Auth::SharedAccessSigner.new(key, secret)
14
14
  @interface ||= Azure::ServiceBus::ServiceBusService.new(host, signer: signer)
15
15
  end
16
16
 
17
+ # To encapsulate the underlying bus object we provide a custom interface
18
+ # for the methods of the Azure smb we use
19
+ def create_topic(name)
20
+ @interface.create_topic(name)
21
+ end
22
+
23
+ def delete_topic(name)
24
+ @interface.delete_topic(name)
25
+ end
26
+
17
27
  # This method returns a list of topics currently defined on the Bifrost
18
28
  def topics
19
29
  @interface.list_topics.map do |t|
20
30
  Topic.new(t.name)
21
31
  end
22
32
  end
33
+
34
+ # Tells us if the topic has already been defined
35
+ def topic_exists?(topic)
36
+ topics.include?(topic)
37
+ end
38
+
39
+ private
40
+
41
+ # Simple utlity method to keep the code legible
42
+ def key
43
+ ENV['AZURE_BUS_KEY_NAME']
44
+ end
45
+
46
+ def secret
47
+ ENV['AZURE_BUS_KEY_SECRET']
48
+ end
23
49
  end
24
50
  end
data/lib/bifrost/topic.rb CHANGED
@@ -13,21 +13,12 @@ module Bifrost
13
13
  super()
14
14
  end
15
15
 
16
- # If the topic has been defined this method returns true, if not
17
- # it returns false
18
- def exists?
19
- @bus.topics.each do |topic|
20
- return true if topic.name == name
21
- end
22
- false
23
- end
24
-
25
16
  # If a topic has not been defined we can save it, so it becomes defined
26
17
  def save
27
18
  if exists?
28
19
  false
29
20
  else
30
- @bus.interface.create_topic(name)
21
+ @bus.create_topic(name)
31
22
  true
32
23
  end
33
24
  end
@@ -35,7 +26,7 @@ module Bifrost
35
26
  # If a topic is defined, we can remove the definition
36
27
  def delete
37
28
  if exists?
38
- @bus.interface.delete_topic(name)
29
+ @bus.delete_topic(name)
39
30
  true
40
31
  else
41
32
  false
@@ -71,5 +62,15 @@ module Bifrost
71
62
  false
72
63
  end
73
64
  end
65
+
66
+ def ==(another_topic)
67
+ self.name == another_topic.name && self.class == another_topic.class
68
+ end
69
+
70
+ # Topics are self aware, and know if they exist or not, but only with the help
71
+ # of the almighty bus
72
+ def exists?
73
+ @bus.topic_exists?(self)
74
+ end
74
75
  end
75
76
  end
@@ -9,7 +9,7 @@ module Bifrost
9
9
 
10
10
  # The patch version of Bifrost, updated only for bug fixes from the last
11
11
  # feature release.
12
- PATCH_VERSION = 3
12
+ PATCH_VERSION = 4
13
13
 
14
14
  # The full version as a string.
15
15
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bifrost::Bus do
4
+ let(:bus) { Bifrost::Bus.new }
5
+
6
+ context 'for an undefined topic' do
7
+ it 'should return false for defined?' do
8
+ new_topic = Bifrost::Topic.new('new-topic')
9
+ expect(bus.topic_exists?(new_topic)).to be_falsey
10
+ end
11
+ end
12
+
13
+ context 'for a defined topic' do
14
+ it 'should return true for defined?' do
15
+ topic = Bifrost::Topic.new('bus-topic')
16
+ topic.save
17
+ dup_topic = Bifrost::Topic.new('bus-topic')
18
+ expect(bus.topic_exists?(dup_topic)).to be_truthy
19
+ topic.delete
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,6 @@ describe Bifrost::Topic do
5
5
  subject(:topic) { Bifrost::Topic.new('topic_name') }
6
6
 
7
7
  it { is_expected.to respond_to(:name) }
8
- it { is_expected.to respond_to(:exists?) }
9
8
  it { is_expected.to respond_to(:save) }
10
9
  it { is_expected.to respond_to(:delete) }
11
10
  it { is_expected.to respond_to(:add_subscriber) }
@@ -16,11 +15,23 @@ describe Bifrost::Topic do
16
15
  expect { invalid_topic.save }.to raise_error(TypeError)
17
16
  end
18
17
 
19
- context 'for an undefined topic' do
20
- it 'should return false for defined?' do
21
- expect(topic.exists?).to be_falsey
18
+ describe 'equality' do
19
+ it 'should return true for the same object' do
20
+ expect(topic).to eq(topic)
21
+ end
22
+
23
+ it 'should return true for topics with the same name' do
24
+ same_topic = Bifrost::Topic.new('topic_name')
25
+ expect(same_topic).to eq(topic)
22
26
  end
23
27
 
28
+ it 'should return false for topics with disimilar names' do
29
+ different_topic = Bifrost::Topic.new('different_topic_name')
30
+ expect(different_topic).not_to eq(topic)
31
+ end
32
+ end
33
+
34
+ context 'for an undefined topic' do
24
35
  it 'should persist the topic' do
25
36
  new_topic = Bifrost::Topic.new('new_topic_name')
26
37
  expect(new_topic.save).to be_truthy
@@ -46,17 +57,15 @@ describe Bifrost::Topic do
46
57
  let(:new_topic) { Bifrost::Topic.new('test_donotdelete') }
47
58
 
48
59
  before(:all) do
60
+ bus = Bifrost::Bus.new
49
61
  tp = Bifrost::Topic.new('test_donotdelete')
50
- tp.save unless tp.exists?
62
+ tp.save unless bus.topic_exists?(tp)
51
63
  end
52
64
 
53
65
  after(:all) do
66
+ bus = Bifrost::Bus.new
54
67
  tp = Bifrost::Topic.new('test_donotdelete')
55
- tp.delete if tp.exists?
56
- end
57
-
58
- it 'should return true for defined?' do
59
- expect(new_topic.exists?).to be_truthy
68
+ tp.delete if bus.topic_exists?(tp)
60
69
  end
61
70
 
62
71
  it 'should return false for save' do
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'azure'
2
+ require 'bifrost'
2
3
  require 'byebug'
3
4
  require 'dotenv'
4
5
  require 'simplecov'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bi-frost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shirren Premaratne
@@ -171,6 +171,7 @@ files:
171
171
  - lib/bifrost/topic.rb
172
172
  - lib/bifrost/version.rb
173
173
  - lib/bifrost/worker.rb
174
+ - spec/bifrost/bus_spec.rb
174
175
  - spec/bifrost/manager_spec.rb
175
176
  - spec/bifrost/message_spec.rb
176
177
  - spec/bifrost/subscriber_spec.rb
@@ -204,6 +205,7 @@ specification_version: 4
204
205
  summary: Bifrost is a pub/sub wrapper library which uses the Azure message bus and
205
206
  actors.
206
207
  test_files:
208
+ - spec/bifrost/bus_spec.rb
207
209
  - spec/bifrost/manager_spec.rb
208
210
  - spec/bifrost/message_spec.rb
209
211
  - spec/bifrost/subscriber_spec.rb