stomping_ground 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,47 +10,48 @@ module StompingGround
10
10
  attr_writer :queue_name
11
11
  attr_writer :sent_message_dir
12
12
 
13
- def post_init
14
- end
15
-
16
- def receive_data frame
17
- frame_info = parse(frame)
18
- case frame_info[:command]
19
- when "CONNECT"
20
- send_data "CONNECTED\n"
21
- send_data "version:1.1\n"
22
- send_data "\n"
23
- send_data "\0"
24
- when "SUBSCRIBE"
25
- if @queue_name.nil? || frame_info[:destination] == @queue_name
26
- message = @message_body || "hello"
27
- send_data "MESSAGE\n"
28
- send_data "subscription:#{frame_info[:id]}\n"
29
- send_data "message-id:007\n"
30
- send_data "destination:#{frame_info[:destination]}\n"
31
- send_data "content-type:text/plain\n"
32
- send_data "content-length:#{message.length}\n"
13
+ def post_init; end
14
+ def unbind; end
15
+
16
+ def receive_data data
17
+ append_data(data)
18
+
19
+ each_frame do |frame|
20
+ frame_info = parse(frame)
21
+ case frame_info[:command]
22
+ when "CONNECT"
23
+ send_data "CONNECTED\n"
24
+ send_data "version:1.1\n"
33
25
  send_data "\n"
34
- send_data "#{message}\0"
35
- end
36
- when "DISCONNECT"
37
- send_data "RECEIPT\n"
38
- send_data "receipt-id:99\n"
39
- send_data "\0"
40
- close_connection
41
- when "SEND"
42
- filename = sent_message_filename_for(frame)
43
- if filename
44
- dirname = File.dirname(filename)
45
- FileUtils.mkdir_p(dirname) if !File.exists?(dirname)
46
- File.open(filename, "w") { |file| file.write(frame) }
26
+ send_data "\0"
27
+ when "SUBSCRIBE"
28
+ if @queue_name.nil? || frame_info[:destination] == @queue_name
29
+ message = @message_body || "hello"
30
+ send_data "MESSAGE\n"
31
+ send_data "subscription:#{frame_info[:id]}\n"
32
+ send_data "message-id:007\n"
33
+ send_data "destination:#{frame_info[:destination]}\n"
34
+ send_data "content-type:text/plain\n"
35
+ send_data "content-length:#{message.length}\n"
36
+ send_data "\n"
37
+ send_data "#{message}\0"
38
+ end
39
+ when "DISCONNECT"
40
+ send_data "RECEIPT\n"
41
+ send_data "receipt-id:99\n"
42
+ send_data "\0"
43
+ close_connection
44
+ when "SEND"
45
+ filename = sent_message_filename_for(frame)
46
+ if filename
47
+ dirname = File.dirname(filename)
48
+ FileUtils.mkdir_p(dirname) if !File.exists?(dirname)
49
+ File.open(filename, "w") { |file| file.write(frame) }
50
+ end
47
51
  end
48
52
  end
49
53
  end
50
54
 
51
- def unbind
52
- end
53
-
54
55
  private
55
56
 
56
57
  def sent_message_filename_for(frame)
@@ -71,6 +72,16 @@ module StompingGround
71
72
  frame_info
72
73
  end
73
74
 
75
+ def append_data data
76
+ (@data ||= '') << data
77
+ end
78
+
79
+ def each_frame(&block)
80
+ while eoframe = @data.index("\0")
81
+ block.call(@data.slice!(0, eoframe + 1))
82
+ end
83
+ end
84
+
74
85
  end
75
86
 
76
87
  class Server
@@ -1,5 +1,5 @@
1
1
  module StompingGround
2
2
  MAJOR=0
3
- MINOR=7
3
+ MINOR=8
4
4
  VERSION="#{MAJOR}.#{MINOR}"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stomping_ground
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: onstomp
16
- requirement: &2156662680 !ruby/object:Gem::Requirement
16
+ requirement: &2164724020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156662680
24
+ version_requirements: *2164724020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2156662240 !ruby/object:Gem::Requirement
27
+ requirement: &2164723560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156662240
35
+ version_requirements: *2164723560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &2156661760 !ruby/object:Gem::Requirement
38
+ requirement: &2164723120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156661760
46
+ version_requirements: *2164723120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &2156661220 !ruby/object:Gem::Requirement
49
+ requirement: &2164722540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156661220
57
+ version_requirements: *2164722540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: eventmachine
60
- requirement: &2156660360 !ruby/object:Gem::Requirement
60
+ requirement: &2164721780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2156660360
68
+ version_requirements: *2164721780
69
69
  description:
70
70
  email:
71
71
  executables: []