drama_queen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/History.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +193 -0
- data/Rakefile +6 -0
- data/drama_queen.gemspec +25 -0
- data/lib/drama_queen.rb +37 -0
- data/lib/drama_queen/consumer.rb +34 -0
- data/lib/drama_queen/exchange.rb +137 -0
- data/lib/drama_queen/producer.rb +32 -0
- data/lib/drama_queen/version.rb +3 -0
- data/spec/acceptance/drama_city_spec.rb +100 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/drama_queen/consumer_spec.rb +49 -0
- data/spec/unit/drama_queen/exchange_spec.rb +252 -0
- data/spec/unit/drama_queen/producer_spec.rb +96 -0
- data/spec/unit/drama_queen_spec.rb +57 -0
- data/test.rb +163 -0
- metadata +116 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'drama_queen'
|
3
|
+
|
4
|
+
|
5
|
+
describe DramaQueen do
|
6
|
+
subject do
|
7
|
+
described_class
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:exchange) { double 'DramaQueen::Exchange' }
|
11
|
+
|
12
|
+
describe '.exchanges' do
|
13
|
+
it 'is created as an empty Array' do
|
14
|
+
expect(subject.exchanges).to be_an_instance_of Array
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.exchange_for' do
|
19
|
+
before do
|
20
|
+
allow(subject).to receive(:exchanges) { [exchange] }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'does not route' do
|
24
|
+
before { allow(exchange).to receive(:routing_key) { 'another key' } }
|
25
|
+
specify { expect(subject.exchange_for 'test_key').to eq nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'does route' do
|
29
|
+
before { allow(exchange).to receive(:routing_key) { 'test_key' } }
|
30
|
+
specify { expect(subject.exchange_for 'test_key').to eq exchange }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.routes_to?' do
|
35
|
+
before do
|
36
|
+
allow(subject).to receive(:exchanges) { [exchange] }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'does not route' do
|
40
|
+
before do
|
41
|
+
allow(subject).to receive(:exchange_for).
|
42
|
+
with('test_key') { false }
|
43
|
+
end
|
44
|
+
|
45
|
+
specify { expect(subject.routes_to? 'test_key').to eq false }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'does route' do
|
49
|
+
before do
|
50
|
+
allow(subject).to receive(:exchange_for).
|
51
|
+
with('test_key') { true }
|
52
|
+
end
|
53
|
+
|
54
|
+
specify { expect(subject.routes_to? 'test_key').to eq true }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
=begin
|
2
|
+
require './lib/drama_queen/producer'
|
3
|
+
require './lib/drama_queen/consumer'
|
4
|
+
|
5
|
+
class A
|
6
|
+
include DramaQueen::Consumer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
subscribe 'root.*.children', :call_me
|
10
|
+
end
|
11
|
+
|
12
|
+
def call_me(*args)
|
13
|
+
puts "A got called with args: #{args}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class B
|
18
|
+
include DramaQueen::Producer
|
19
|
+
|
20
|
+
def do_stuff
|
21
|
+
publish 'root.parent', 1, 2, 3
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class C
|
26
|
+
include DramaQueen::Producer
|
27
|
+
|
28
|
+
def do_stuff
|
29
|
+
publish 'root.parent.children', 1, 2, 3
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
a = A.new
|
35
|
+
b = B.new
|
36
|
+
c = C.new
|
37
|
+
|
38
|
+
puts 'B...'
|
39
|
+
b.do_stuff
|
40
|
+
puts 'C...'
|
41
|
+
c.do_stuff
|
42
|
+
=end
|
43
|
+
|
44
|
+
=begin
|
45
|
+
require './lib/drama_queen/producer'
|
46
|
+
|
47
|
+
class A
|
48
|
+
include DramaQueen::Producer
|
49
|
+
|
50
|
+
def do_stuff
|
51
|
+
criteria = -> { true }
|
52
|
+
publish criteria, "I'm doing the stuff111111111"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
require './lib/drama_queen/consumer'
|
58
|
+
|
59
|
+
class B
|
60
|
+
include DramaQueen::Consumer
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
criteria = -> { true }
|
64
|
+
subscribe criteria, :call_me
|
65
|
+
end
|
66
|
+
|
67
|
+
def call_me(msg)
|
68
|
+
puts msg
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
a = A.new
|
73
|
+
b = B.new
|
74
|
+
|
75
|
+
a.do_stuff
|
76
|
+
=end
|
77
|
+
|
78
|
+
|
79
|
+
def routes? first, second
|
80
|
+
first_minus_second = first - second
|
81
|
+
second_minus_first = second - first
|
82
|
+
puts "first: #{first}"
|
83
|
+
puts "second: #{second}"
|
84
|
+
puts "first minus second: #{first - second}"
|
85
|
+
puts "second minus first: #{second - first}"
|
86
|
+
puts "first size: #{first.size}"
|
87
|
+
puts "second size: #{second.size}"
|
88
|
+
|
89
|
+
puts 'first loop'
|
90
|
+
first.each_cons(second.size) { |e| p e }
|
91
|
+
puts 'second loop'
|
92
|
+
second.each_cons(first.size) { |e| p e }
|
93
|
+
|
94
|
+
if first == second
|
95
|
+
true
|
96
|
+
elsif (first_minus_second).uniq == %w[*] && first.size == second.size
|
97
|
+
true
|
98
|
+
elsif first_minus_second.all? { |e| e =~ Regexp.new(second_minus_first.join('.'))}
|
99
|
+
true
|
100
|
+
=begin
|
101
|
+
elsif (second_minus_first).size == (first_minus_second).size &&
|
102
|
+
first.size == second.size &&
|
103
|
+
first_minus_second =~ second_minus_first
|
104
|
+
true
|
105
|
+
=end
|
106
|
+
else
|
107
|
+
false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
a = %w[root parent child]
|
112
|
+
b = %w[root * child]
|
113
|
+
c = %w[root parent meow]
|
114
|
+
d = %w[root parent *]
|
115
|
+
e = %w[root * child *]
|
116
|
+
f = %w[root parent child thing]
|
117
|
+
|
118
|
+
puts '-' * 40
|
119
|
+
puts '-' * 40
|
120
|
+
puts 'A' * 40
|
121
|
+
puts "a should route to a: #{routes? a, a}"
|
122
|
+
puts '-' * 40
|
123
|
+
|
124
|
+
puts "a should route to b: #{routes? a, b}"
|
125
|
+
puts '-' * 40
|
126
|
+
|
127
|
+
puts "a should NOT route to c: #{routes? a, c}"
|
128
|
+
puts '-' * 40
|
129
|
+
|
130
|
+
puts "a should route to d: #{routes? a, d}"
|
131
|
+
puts '-' * 40
|
132
|
+
|
133
|
+
puts "a should NOT route to e: #{routes? a, e}"
|
134
|
+
puts '-' * 40
|
135
|
+
|
136
|
+
puts "a should NOT route to f: #{routes? a, f}"
|
137
|
+
puts '-' * 40
|
138
|
+
|
139
|
+
=begin
|
140
|
+
puts '-' * 40
|
141
|
+
puts '-' * 40
|
142
|
+
puts 'B' * 40
|
143
|
+
puts "b should route to a: #{routes? b, a}"
|
144
|
+
puts '-' * 40
|
145
|
+
|
146
|
+
puts "b should route to b: #{routes? b, b}"
|
147
|
+
puts '-' * 40
|
148
|
+
|
149
|
+
puts "b should NOT route to c: #{routes? b, c}"
|
150
|
+
puts '-' * 40
|
151
|
+
|
152
|
+
puts "b should route to d: #{routes? b, d}"
|
153
|
+
puts '-' * 40
|
154
|
+
|
155
|
+
puts "b should NOT route to e: #{routes? b, e}"
|
156
|
+
puts '-' * 40
|
157
|
+
|
158
|
+
puts "b should NOT route to f: #{routes? b, f}"
|
159
|
+
puts '-' * 40
|
160
|
+
|
161
|
+
puts "c should NOT route to a: #{routes? c, a}"
|
162
|
+
puts '-' * 40
|
163
|
+
=end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drama_queen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Loveless
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0.beta1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0.beta1
|
55
|
+
description: |-
|
56
|
+
A simple, non-threaded, local-object pub-sub/observer
|
57
|
+
with the ability to pub-sub on topics. Topics can be any Ruby object.
|
58
|
+
email: steve.loveless@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- History.md
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- drama_queen.gemspec
|
72
|
+
- lib/drama_queen.rb
|
73
|
+
- lib/drama_queen/consumer.rb
|
74
|
+
- lib/drama_queen/exchange.rb
|
75
|
+
- lib/drama_queen/producer.rb
|
76
|
+
- lib/drama_queen/version.rb
|
77
|
+
- spec/acceptance/drama_city_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/unit/drama_queen/consumer_spec.rb
|
80
|
+
- spec/unit/drama_queen/exchange_spec.rb
|
81
|
+
- spec/unit/drama_queen/producer_spec.rb
|
82
|
+
- spec/unit/drama_queen_spec.rb
|
83
|
+
- test.rb
|
84
|
+
homepage: https://githb.com/turboladen/drama_queen
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.1.9
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: A simple, non-threaded, local-object pub-sub/observer with the ability to
|
108
|
+
pub-sub on topics. Topics can be any Ruby object.
|
109
|
+
test_files:
|
110
|
+
- spec/acceptance/drama_city_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/unit/drama_queen/consumer_spec.rb
|
113
|
+
- spec/unit/drama_queen/exchange_spec.rb
|
114
|
+
- spec/unit/drama_queen/producer_spec.rb
|
115
|
+
- spec/unit/drama_queen_spec.rb
|
116
|
+
has_rdoc:
|