ragnar 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,7 +31,10 @@ The following code with Ragnar creates a single topic subscription on the 'event
31
31
 
32
32
  Ragnar.exchange(:topic, 'events') do |x|
33
33
  x.queue_prefix = :myservice # optional
34
- x.subscribe('the.event.name') do |message|
34
+ x.subscribe('the.event.name') do |headers, payload|
35
+ # subscription code
36
+ end
37
+ x.subscribe(:queue => 'my.queue', :routing_key => '#.name') do |headers, payload|
35
38
  # subscription code
36
39
  end
37
40
  end
@@ -44,6 +47,9 @@ The equivalent AMQP code for the code above would be:
44
47
  channel.queue('myservice.the.event.name').bind(exchange, :routing_key => 'the.event.name').subscribe do |headers, payload|
45
48
  # subscription code
46
49
  end
50
+ channel.queue('my.queue').bind(exchange, :routing_key => '#.name').subscribe do |headers, payload|
51
+ # subscription code
52
+ end
47
53
  end
48
54
 
49
55
  ### Feedback ###
@@ -1,3 +1,3 @@
1
1
  module Ragnar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/ragnar.rb CHANGED
@@ -6,23 +6,9 @@ module Ragnar
6
6
  module_function
7
7
 
8
8
  def exchange type, name, options={}
9
- exch = exchanges[key(type, name)] || store(Ragnar::Exchange.new(type, name, options))
10
- yield(exch) if block_given?
11
- exch
9
+ x = Ragnar::Exchange.new(type, name, options)
10
+ yield(x) if block_given?
11
+ x
12
12
  end
13
-
14
- def store ex
15
- exchanges[key(ex.type, ex.name)] = ex
16
- end
17
-
18
- def exchanges
19
- @exchanges ||= {}
20
- end
21
-
22
- def key type, name
23
- '%s-%s' % [type.to_s, name]
24
- end
25
-
26
- private :store, :exchanges, :key
27
13
 
28
14
  end
@@ -16,9 +16,9 @@ describe Ragnar do
16
16
  end
17
17
 
18
18
  context 'when the exchange already has been created locally' do
19
- it 'uses the existing exchange' do
19
+ it 'creates a new exchange' do
20
20
  exch = Ragnar.exchange(:topic, 'exch_name')
21
- Ragnar.exchange(:topic, 'exch_name').should === exch
21
+ Ragnar.exchange(:topic, 'exch_name').should_not === exch
22
22
  done
23
23
  end
24
24
  end
@@ -27,20 +27,20 @@ describe Ragnar do
27
27
  it 'registers the subscriptions with the exchange' do
28
28
  subscriber = Proc.new{|message| true }
29
29
  exchange = Ragnar::Exchange.new(:topic, 'events')
30
- Ragnar.should_receive(:store).and_return(exchange)
30
+ Ragnar.should_receive(:exchange).and_yield(exchange)
31
31
 
32
32
  exchange.should_receive(:queue_prefix=).with(:my_service)
33
- exchange.should_receive(:subscribe).with('the.message.route.1', subscriber)
34
- exchange.should_receive(:subscribe).with('the.message.route.2', subscriber)
35
- exchange.should_receive(:subscribe).with('the.message.route.3', subscriber)
36
- exchange.should_receive(:subscribe).with('the.message.route.4', subscriber)
33
+ exchange.should_receive(:subscribe).with('the.message.route.1', &subscriber)
34
+ exchange.should_receive(:subscribe).with('the.message.route.2', &subscriber)
35
+ exchange.should_receive(:subscribe).with('the.message.route.3', &subscriber)
36
+ exchange.should_receive(:subscribe).with('the.message.route.4', &subscriber)
37
37
 
38
38
  Ragnar.exchange(:topic, 'events') do |x|
39
39
  x.queue_prefix = :my_service
40
- x.subscribe('the.message.route.1', subscriber)
41
- x.subscribe('the.message.route.2', subscriber)
42
- x.subscribe('the.message.route.3', subscriber)
43
- x.subscribe('the.message.route.4', subscriber)
40
+ x.subscribe('the.message.route.1', &subscriber)
41
+ x.subscribe('the.message.route.2', &subscriber)
42
+ x.subscribe('the.message.route.3', &subscriber)
43
+ x.subscribe('the.message.route.4', &subscriber)
44
44
  end
45
45
 
46
46
  done
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragnar
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
4
+ prerelease:
5
+ version: 0.1.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - BJ Neislen
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-05-06 00:00:00 -06:00
18
- default_executable:
13
+ date: 2011-07-20 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: amqp
@@ -25,10 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 7
31
- - 1
32
23
  version: 0.7.1
33
24
  type: :runtime
34
25
  version_requirements: *id001
@@ -40,10 +31,6 @@ dependencies:
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 2
45
- - 5
46
- - 0
47
34
  version: 2.5.0
48
35
  type: :development
49
36
  version_requirements: *id002
@@ -55,10 +42,6 @@ dependencies:
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 4
61
- - 1
62
45
  version: 0.4.1
63
46
  type: :development
64
47
  version_requirements: *id003
@@ -85,7 +68,6 @@ files:
85
68
  - spec/lib/ragnar/exchange_spec.rb
86
69
  - spec/lib/ragnar_spec.rb
87
70
  - spec/spec_helper.rb
88
- has_rdoc: true
89
71
  homepage: http://www.rand9.com
90
72
  licenses: []
91
73
 
@@ -99,21 +81,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
81
  requirements:
100
82
  - - ">="
101
83
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
84
  version: "0"
105
85
  required_rubygems_version: !ruby/object:Gem::Requirement
106
86
  none: false
107
87
  requirements:
108
88
  - - ">="
109
89
  - !ruby/object:Gem::Version
110
- segments:
111
- - 0
112
90
  version: "0"
113
91
  requirements: []
114
92
 
115
93
  rubyforge_project: ragnar
116
- rubygems_version: 1.3.7
94
+ rubygems_version: 1.8.2
117
95
  signing_key:
118
96
  specification_version: 3
119
97
  summary: Provide top-level pub/sub methods with RabbitMQ (AMQP) for interacting with a larger service ecosystem