stomper 0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +63 -11
- data/lib/stomper.rb +13 -1
- data/lib/stomper/client.rb +3 -284
- data/lib/stomper/connection.rb +67 -114
- data/lib/stomper/frame_reader.rb +73 -0
- data/lib/stomper/frame_writer.rb +21 -0
- data/lib/stomper/frames.rb +24 -9
- data/lib/stomper/frames/abort.rb +2 -6
- data/lib/stomper/frames/ack.rb +2 -6
- data/lib/stomper/frames/begin.rb +2 -5
- data/lib/stomper/frames/client_frame.rb +30 -27
- data/lib/stomper/frames/commit.rb +1 -5
- data/lib/stomper/frames/connect.rb +2 -7
- data/lib/stomper/frames/connected.rb +11 -8
- data/lib/stomper/frames/disconnect.rb +1 -4
- data/lib/stomper/frames/error.rb +3 -8
- data/lib/stomper/frames/message.rb +15 -11
- data/lib/stomper/frames/receipt.rb +1 -6
- data/lib/stomper/frames/send.rb +1 -5
- data/lib/stomper/frames/server_frame.rb +13 -23
- data/lib/stomper/frames/subscribe.rb +9 -14
- data/lib/stomper/frames/unsubscribe.rb +3 -7
- data/lib/stomper/open_uri_interface.rb +41 -0
- data/lib/stomper/receipt_handlers.rb +23 -0
- data/lib/stomper/receiptor.rb +38 -0
- data/lib/stomper/sockets.rb +37 -0
- data/lib/stomper/subscriber.rb +76 -0
- data/lib/stomper/subscription.rb +14 -14
- data/lib/stomper/threaded_receiver.rb +59 -0
- data/lib/stomper/transaction.rb +13 -8
- data/lib/stomper/transactor.rb +50 -0
- data/lib/stomper/uri.rb +55 -0
- data/spec/client_spec.rb +7 -158
- data/spec/connection_spec.rb +13 -3
- data/spec/frame_reader_spec.rb +37 -0
- data/spec/frame_writer_spec.rb +27 -0
- data/spec/frames/client_frame_spec.rb +22 -98
- data/spec/frames/indirect_frame_spec.rb +45 -0
- data/spec/frames/server_frame_spec.rb +15 -16
- data/spec/open_uri_interface_spec.rb +132 -0
- data/spec/receiptor_spec.rb +35 -0
- data/spec/shared_connection_examples.rb +12 -17
- data/spec/spec_helper.rb +6 -0
- data/spec/subscriber_spec.rb +77 -0
- data/spec/subscription_spec.rb +11 -11
- data/spec/subscriptions_spec.rb +3 -6
- data/spec/threaded_receiver_spec.rb +33 -0
- data/spec/transaction_spec.rb +5 -5
- data/spec/transactor_spec.rb +46 -0
- metadata +30 -6
- data/lib/stomper/frames/headers.rb +0 -68
- data/spec/frames/headers_spec.rb +0 -54
@@ -1,68 +0,0 @@
|
|
1
|
-
module Stomper
|
2
|
-
module Frames
|
3
|
-
# Encapsulates the headers attached to a Frame from the Stomper::Frames
|
4
|
-
# module. Instances of this class wrap a hash, but do so in a way
|
5
|
-
# to allow its values to be accessed by string, symbol, or method name,
|
6
|
-
# similar to an OpenStruct.
|
7
|
-
class Headers
|
8
|
-
# Creates a new Header instance, derived from the supplied hash, +hsh+.
|
9
|
-
def initialize(hsh = {})
|
10
|
-
@intern_head = hsh.inject({}) { |acc, (k,v)| acc[k.to_sym] = v; acc }
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns the 'id' header value, if it exists. Explicitly implemented
|
14
|
-
# because Object#id is a valid method by default.
|
15
|
-
def id
|
16
|
-
@intern_head[:id]
|
17
|
-
end
|
18
|
-
|
19
|
-
# Assigns the 'id' header value. Explicitly implemented because Object#id
|
20
|
-
# is a valid method, and we implemented +id+ explicitly so why not +id=+
|
21
|
-
def id=(id)
|
22
|
-
@intern_head[:id] = id
|
23
|
-
end
|
24
|
-
|
25
|
-
# Allows the headers to be accessed as though they were a Hash instance.
|
26
|
-
def [](idx)
|
27
|
-
@intern_head[idx.to_sym]
|
28
|
-
end
|
29
|
-
|
30
|
-
# Allows the headers to be assigned as though they were a Hash instance.
|
31
|
-
def []=(idx, val)
|
32
|
-
@intern_head[idx.to_sym] = val
|
33
|
-
end
|
34
|
-
|
35
|
-
def method_missing(meth, *args) # :nodoc:
|
36
|
-
raise TypeError, "can't modify frozen headers" if frozen?
|
37
|
-
meth_str = meth.to_s
|
38
|
-
ret = if meth_str =~ /=$/
|
39
|
-
raise ArgumentError, "setter #{meth_str} can only accept one value" if args.size != 1
|
40
|
-
meth_str.chop!
|
41
|
-
@intern_head[meth_str.to_sym] = args.first
|
42
|
-
else
|
43
|
-
raise ArgumentError, "getter #{meth_str} cannot accept any values" if args.size > 0
|
44
|
-
@intern_head[meth_str.to_sym]
|
45
|
-
end
|
46
|
-
_create_helpers(meth_str)
|
47
|
-
# Do the appropriate thing the first time around.
|
48
|
-
ret
|
49
|
-
end
|
50
|
-
|
51
|
-
# Converts the headers encapsulated by this object into a format that
|
52
|
-
# the Stomp Protocol expects them to be presented as.
|
53
|
-
def to_stomp
|
54
|
-
@intern_head.sort { |a, b| a.first.to_s <=> b.first.to_s }.inject("") do |acc, (k,v)|
|
55
|
-
acc << "#{k.to_s}:#{v}\n"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
protected
|
60
|
-
def _create_helpers(meth)
|
61
|
-
return if self.respond_to?(meth)
|
62
|
-
meta = class << self; self; end
|
63
|
-
meta.send(:define_method, meth) { self[meth] }
|
64
|
-
meta.send(:define_method, :"#{meth}=") { |v| self[meth] = v }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/spec/frames/headers_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
module Stomper::Frames
|
4
|
-
describe Headers do
|
5
|
-
before(:each) do
|
6
|
-
@headers = Headers.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should set a header by a string key, accessible by all" do
|
10
|
-
@test_value = "a test"
|
11
|
-
@headers['testing'] = @test_value
|
12
|
-
@headers['testing'].should == @test_value
|
13
|
-
@headers[:testing].should == @test_value
|
14
|
-
@headers.testing.should == @test_value
|
15
|
-
@headers.send(:testing).should == @test_value
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should set a header by a symbol key, accessible by all" do
|
19
|
-
@test_value = "another test"
|
20
|
-
@headers[:some_key] = @test_value
|
21
|
-
@headers['some_key'].should == @test_value
|
22
|
-
@headers[:some_key].should == @test_value
|
23
|
-
@headers.some_key.should == @test_value
|
24
|
-
@headers.send(:some_key).should == @test_value
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should set a header by a method, accessible by all" do
|
28
|
-
@test_value = "yet more testing"
|
29
|
-
@headers.another_key = @test_value
|
30
|
-
@headers['another_key'].should == @test_value
|
31
|
-
@headers[:another_key].should == @test_value
|
32
|
-
@headers.another_key.should == @test_value
|
33
|
-
@headers.send(:another_key).should == @test_value
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should override the default id getter and provide a setter" do
|
37
|
-
@test_value = "my id"
|
38
|
-
@headers.id = @test_value
|
39
|
-
@headers.id.should == @test_value
|
40
|
-
@headers['id'].should == @test_value
|
41
|
-
@headers[:id].should == @test_value
|
42
|
-
@headers.send(:id).should == @test_value
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should provide method to convert to stomp compatible headers" do
|
46
|
-
@headers.to_stomp.should be_empty
|
47
|
-
@headers.ack = 'auto'
|
48
|
-
@headers.destination = '/queue/test/1'
|
49
|
-
@headers.to_stomp.should == "ack:auto\ndestination:/queue/test/1\n"
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|