socky 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,16 @@
1
1
  h1. Changelog
2
2
 
3
+ h2. 0.1.0 / 2010-08-03
4
+
5
+ *IMPORTANT! This version will not work with plugin version lower than 0.1.0*
6
+
7
+ * new features:
8
+ ** server now send authentication status
9
+ ** new syntax
10
+ ** option to exclude clients/channels
11
+ * bugfixes:
12
+ ** none
13
+
3
14
  h2. 0.0.9 / 2010-06-20
4
15
 
5
16
  *IMPORTANT! This version will not work with plugin version lower than 0.0.9*
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.1.0
data/bin/socky CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require File.join(File.dirname(__FILE__), '..', 'lib', 'socky')
4
+ require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib', 'socky')
5
5
  Socky::Runner.run
@@ -60,5 +60,4 @@ require 'socky/options'
60
60
  require 'socky/runner'
61
61
  require 'socky/connection'
62
62
  require 'socky/net_request'
63
- require 'socky/server'
64
63
  require 'socky/message'
@@ -38,6 +38,8 @@ module Socky
38
38
 
39
39
  def channels
40
40
  @channels ||= query["channels"].to_s.split(",").collect(&:strip).reject(&:empty?)
41
+ @channels[0] ||= nil # Every user should have at last one channel
42
+ @channels
41
43
  end
42
44
 
43
45
  def subscribe
@@ -8,9 +8,11 @@ module Socky
8
8
  if response
9
9
  debug [self.name, "authentication successed"]
10
10
  add_to_pool
11
+ send_authentication("success")
11
12
  @authenticated_by_url = true
12
13
  else
13
14
  debug [self.name, "authentication failed"]
15
+ send_authentication("failure")
14
16
  disconnect
15
17
  end
16
18
  end unless admin || authenticated?
@@ -23,6 +25,10 @@ module Socky
23
25
  end
24
26
  end
25
27
 
28
+ def send_authentication(msg)
29
+ send_data({:type => :authentication, :body => msg})
30
+ end
31
+
26
32
  def authenticated?
27
33
  @authenticated ||= (admin ? authenticate_as_admin : authenticate_as_user)
28
34
  end
@@ -12,35 +12,42 @@ module Socky
12
12
  end
13
13
 
14
14
  def find(opts = {})
15
- clients = opts[:clients].to_a
16
- channels = opts[:channels].to_a
15
+ to = symbolize_keys(opts[:to]) || {}
16
+ exclude = symbolize_keys(opts[:except]) || {}
17
+
17
18
  connections = find_all
18
- connections = filter_by_clients(connections, clients) unless clients.empty?
19
- connections = filter_by_channels(connections, channels) unless channels.empty?
19
+ connections = filter_by_clients(connections, to[:clients], exclude[:clients])
20
+ connections = filter_by_channels(connections, to[:channels], exclude[:channels])
20
21
 
21
22
  connections
22
23
  end
23
24
 
24
- def find_by_clients(clients)
25
- find(:clients => clients)
26
- end
25
+ private
27
26
 
28
- def find_by_channels(channels)
29
- find(:channels => channels)
30
- end
27
+ def filter_by_clients(connections, included_clients = nil, excluded_clients = nil)
28
+ # Empty table means "no users" - nil means "all users"
29
+ return [] if (included_clients.is_a?(Array) && included_clients.empty?)
31
30
 
32
- def find_by_clients_and_channels(clients, channels)
33
- find(:clients => clients, :channels => channels)
31
+ included_clients = included_clients.to_a
32
+ excluded_clients = excluded_clients.to_a
33
+
34
+ connections.collect do |connection|
35
+ connection if (included_clients.empty? || included_clients.include?(connection.client)) && !excluded_clients.include?(connection.client)
36
+ end.compact
34
37
  end
35
38
 
36
- private
39
+ def filter_by_channels(connections, included_channels = nil, excluded_channels = nil)
40
+ # Empty table means "no channels" - nil means "all channels"
41
+ return [] if (included_channels.is_a?(Array) && included_channels.empty?)
37
42
 
38
- def filter_by_clients(connections, clients)
39
- connections.collect{ |connection| connection if clients.include? connection.client }.compact
40
- end
43
+ included_channels = included_channels.to_a
44
+ excluded_channels = excluded_channels.to_a
41
45
 
42
- def filter_by_channels(connections, channels)
43
- connections.collect{ |connection| connection if channels.any?{ |channel| connection.channels.include?(channel) } }.compact
46
+ connections.collect do |connection|
47
+ connection if connection.channels.any? do |channel|
48
+ (included_channels.empty? || included_channels.include?(channel) ) && !excluded_channels.include?(channel)
49
+ end
50
+ end.compact
44
51
  end
45
52
 
46
53
  end
@@ -38,30 +38,8 @@ module Socky
38
38
  end
39
39
 
40
40
  def broadcast
41
- case params[:type].to_sym
42
- when :to_clients then broadcast_to_clients
43
- when :to_channels then broadcast_to_channels
44
- when :to_clients_on_channels then broadcast_to_clients_on_channels
45
- else raise
46
- end
47
- rescue
48
- raise(InvalidQuery, "unknown broadcast type")
49
- end
50
-
51
- def broadcast_to_clients
52
- verify :clients
53
- Socky::Server.send_to_clients(params[:body], params[:clients])
54
- end
55
-
56
- def broadcast_to_channels
57
- verify :channels
58
- Socky::Server.send_to_channels(params[:body], params[:channels])
59
- end
60
-
61
- def broadcast_to_clients_on_channels
62
- verify :clients
63
- verify :channels
64
- Socky::Server.send_to_clients_on_channels(params[:body], params[:clients], params[:channels])
41
+ connections = Socky::Connection.find(params)
42
+ send_message(params[:body], connections)
65
43
  end
66
44
 
67
45
  def query
@@ -77,14 +55,13 @@ module Socky
77
55
  respond Socky::Connection.find_all
78
56
  end
79
57
 
80
- def verify(field)
81
- params[field] = params[field].to_a unless params[field].is_a?(Array)
82
- params[field] = params[field].collect(&:to_s)
83
- end
84
-
85
58
  def respond(message)
86
59
  creator.send_message(message)
87
60
  end
88
61
 
62
+ def send_message(message, connections)
63
+ connections.each{|connection| connection.send_message message}
64
+ end
65
+
89
66
  end
90
67
  end
@@ -7,6 +7,7 @@ describe Socky::Connection::Authentication do
7
7
  context "#subscribe_request" do
8
8
  before(:each) do
9
9
  stub!(:admin).and_return(false)
10
+ stub!(:send_data)
10
11
  end
11
12
  it "should not call #send_subscribe_request if already authenticated" do
12
13
  stub!(:authenticated?).and_return(true)
@@ -2,10 +2,11 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe Socky::Connection::Finders do
4
4
  include Socky::Connection::Finders
5
+ include Socky::Misc
5
6
 
6
7
  context "class" do
7
8
  before(:each) do
8
- @connection1 = mock(:connection1, :client => "client1", :channels => [])
9
+ @connection1 = mock(:connection1, :client => "client1", :channels => [nil])
9
10
  @connection2 = mock(:connection2, :client => "client1", :channels => ["1", "3", "5"])
10
11
  @connection3 = mock(:connection3, :client => "client2", :channels => ["2", "5"])
11
12
  @connection4 = mock(:connection4, :client => "client3", :channels => ["3", "5"])
@@ -23,74 +24,165 @@ describe Socky::Connection::Finders do
23
24
  it "should return all connections if no options specified" do
24
25
  self.class.find.should eql(@connections)
25
26
  end
26
- context "if :clients option is specified" do
27
- it "should return all connections if :clients is nil or empty" do
28
- self.class.find(:clients => nil).should eql(@connections)
29
- self.class.find(:clients => []).should eql(@connections)
30
- end
31
- it "should return only connections from specified client" do
32
- self.class.find(:clients => "client1").should eql([@connection1,@connection2])
33
- end
34
- it "should return only connections from specified clients if array provided" do
35
- self.class.find(:clients => ["client1","client2"]).should eql([@connection1,@connection2,@connection3])
36
- end
37
- end
38
- context "if :channels option is specified" do
39
- it "should return all connections if :channels is nil or empty" do
40
- self.class.find(:channels => nil).should eql(@connections)
41
- self.class.find(:channels => []).should eql(@connections)
42
- end
43
- it "should return all connections that include specified channel" do
44
- self.class.find(:channels => "3").should eql([@connection2,@connection4])
45
- end
46
- it "should return all connections that include at last one of specified channels" do
47
- self.class.find(:channels => ["2","3"]).should eql([@connection2,@connection3,@connection4])
48
- end
49
- end
50
- context "if both :clients and :channels options are provided" do
51
- context "but :channels are empty" do
27
+ context "on :to" do
28
+ context "if :clients option is specified" do
29
+ it "should return all connections if :clients is nil" do
30
+ self.class.find(:to => {:clients => nil}).should eql(@connections)
31
+ end
32
+ it "should return none connections if :clients is empty" do
33
+ self.class.find(:to => {:clients => []}).should eql([])
34
+ end
52
35
  it "should return only connections from specified client" do
53
- self.class.find(:channels => [],:clients => "client1").should eql([@connection1,@connection2])
36
+ self.class.find(:to => {:clients => "client1"}).should eql([@connection1,@connection2])
54
37
  end
55
38
  it "should return only connections from specified clients if array provided" do
56
- self.class.find(:channels => [],:clients => ["client1","client2"]).should eql([@connection1,@connection2,@connection3])
39
+ self.class.find(:to => {:clients => ["client1","client2"]}).should eql([@connection1,@connection2,@connection3])
57
40
  end
58
41
  end
59
- context "but :clients are empty" do
42
+ context "if :channels option is specified" do
43
+ it "should return all connections if :channels is nil" do
44
+ self.class.find(:to => {:channels => nil}).should eql(@connections)
45
+ end
46
+ it "should return none connections if :channels is empty" do
47
+ self.class.find(:to => {:channels => []}).should eql([])
48
+ end
60
49
  it "should return all connections that include specified channel" do
61
- self.class.find(:clients => [],:channels => "3").should eql([@connection2,@connection4])
50
+ self.class.find(:to => {:channels => "3"}).should eql([@connection2,@connection4])
62
51
  end
63
52
  it "should return all connections that include at last one of specified channels" do
64
- self.class.find(:clients => [],:channels => ["2","3"]).should eql([@connection2,@connection3,@connection4])
53
+ self.class.find(:to => {:channels => ["2","3"]}).should eql([@connection2,@connection3,@connection4])
65
54
  end
66
55
  end
67
- it "should return only connections from specified client that include specified channel" do
68
- self.class.find(:clients => "client1",:channels => "3").should eql([@connection2])
69
- self.class.find(:clients => "client1",:channels => "2").should eql([])
56
+ context "if both :clients and :channels options are provided" do
57
+ context "but :channels are nil" do
58
+ it "should return only connections from specified client" do
59
+ self.class.find(:to => {:channels => nil,:clients => "client1"}).should eql([@connection1,@connection2])
60
+ end
61
+ it "should return only connections from specified clients if array provided" do
62
+ self.class.find(:to => {:channels => nil,:clients => ["client1","client2"]}).should eql([@connection1,@connection2,@connection3])
63
+ end
64
+ end
65
+ context "but :channels are empty" do
66
+ it "should return none connections" do
67
+ self.class.find(:to => {:channels => [],:clients => "client1"}).should eql([])
68
+ end
69
+ it "should return none connections if array provided" do
70
+ self.class.find(:to => {:channels => [],:clients => ["client1","client2"]}).should eql([])
71
+ end
72
+ end
73
+ context "but :clients are nil" do
74
+ it "should return all connections that include specified channel" do
75
+ self.class.find(:to => {:clients => nil,:channels => "3"}).should eql([@connection2,@connection4])
76
+ end
77
+ it "should return all connections that include at last one of specified channels" do
78
+ self.class.find(:to => {:clients => nil,:channels => ["2","3"]}).should eql([@connection2,@connection3,@connection4])
79
+ end
80
+ end
81
+ context "but :clients are empty" do
82
+ it "should return none connections" do
83
+ self.class.find(:to => {:clients => [],:channels => "3"}).should eql([])
84
+ end
85
+ it "should return none connections if array provided" do
86
+ self.class.find(:to => {:clients => [],:channels => ["2","3"]}).should eql([])
87
+ end
88
+ end
89
+ it "should return only connections from specified client that include specified channel" do
90
+ self.class.find(:to => {:clients => "client1",:channels => "3"}).should eql([@connection2])
91
+ self.class.find(:to => {:clients => "client1",:channels => "2"}).should eql([])
92
+ end
93
+ it "should return only connections from specified client that include one of specified channels" do
94
+ self.class.find(:to => {:clients => "client1",:channels => ["2","3"]}).should eql([@connection2])
95
+ end
96
+ it "should return only connections from specified clients that include specified channel" do
97
+ self.class.find(:to => {:clients => ["client1","client2"],:channels => "2"}).should eql([@connection3])
98
+ end
99
+ it "should return only connections from specified clients that include at last one of specified channels" do
100
+ self.class.find(:to => {:clients => ["client1","client2"],:channels => ["2","1"]}).should eql([@connection2,@connection3])
101
+ end
102
+ end
103
+ end
104
+
105
+ context "on :except" do
106
+ context "if :clients option is specified" do
107
+ it "should return all connections if :clients is nil" do
108
+ self.class.find(:except => {:clients => nil}).should eql(@connections)
109
+ end
110
+ it "should return all connections if :clients is empty" do
111
+ self.class.find(:except => {:clients => []}).should eql(@connections)
112
+ end
113
+ it "should return all connections except of specified client" do
114
+ self.class.find(:except => {:clients => "client1"}).should eql([@connection3,@connection4])
115
+ end
116
+ it "should return all connections except of specified clients if array provided" do
117
+ self.class.find(:except => {:clients => ["client1","client2"]}).should eql([@connection4])
118
+ end
70
119
  end
71
- it "should return only connections from specified client that include one of specified channels" do
72
- self.class.find(:clients => "client1",:channels => ["2","3"]).should eql([@connection2])
120
+ context "if :channels option is specified" do
121
+ it "should return all connections if :channels is nil" do
122
+ self.class.find(:except => {:channels => nil}).should eql(@connections)
123
+ end
124
+ it "should return all connections if :channels is empty" do
125
+ self.class.find(:except => {:channels => []}).should eql(@connections)
126
+ end
127
+ it "should return all connections except of that include all specified channels" do
128
+ self.class.find(:except => {:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
129
+ end
73
130
  end
74
- it "should return only connections from specified clients that include specified channel" do
75
- self.class.find(:clients => ["client1","client2"],:channels => "2").should eql([@connection3])
131
+ context "if both :clients and :channels options are provided" do
132
+ context "but :channels are nil" do
133
+ it "should return all connections except of specified client" do
134
+ self.class.find(:except => {:channels => nil,:clients => "client1"}).should eql([@connection3,@connection4])
135
+ end
136
+ it "should return all connections except of specified clients if array provided" do
137
+ self.class.find(:except => {:channels => nil,:clients => ["client1","client2"]}).should eql([@connection4])
138
+ end
139
+ end
140
+ context "but :channels are empty" do
141
+ it "should return all connections except of specified client" do
142
+ self.class.find(:except => {:channels => [],:clients => "client1"}).should eql([@connection3,@connection4])
143
+ end
144
+ it "should return all connections except of provided clients if array provided" do
145
+ self.class.find(:except => {:channels => [],:clients => ["client1","client2"]}).should eql([@connection4])
146
+ end
147
+ end
148
+ context "but :clients are nil" do
149
+ it "should return all connections except of that include all of specified channels" do
150
+ self.class.find(:except => {:clients => nil,:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
151
+ end
152
+ end
153
+ context "but :clients are empty" do
154
+ it "should return all connections except of that include all of specified channels " do
155
+ self.class.find(:except => {:clients => [],:channels => ["2","5"]}).should eql([@connection1,@connection2,@connection4])
156
+ end
157
+ end
158
+ it "should return all connections except of specified client or all specified channels" do
159
+ self.class.find(:except => {:clients => "client2",:channels => "3"}).should eql([@connection1,@connection2,@connection4])
160
+ self.class.find(:except => {:clients => "client2",:channels => ["3","5"]}).should eql([@connection1,@connection2])
161
+ end
162
+ it "should return only connections from specified clients that include specified channel" do
163
+ self.class.find(:except => {:clients => ["client1","client2"],:channels => "3"}).should eql([@connection4])
164
+ self.class.find(:except => {:clients => ["client1","client2"],:channels => ["3","5"]}).should eql([])
165
+ end
76
166
  end
77
- it "should return only connections from specified clients that include at last one of specified channels" do
78
- self.class.find(:clients => ["client1","client2"],:channels => ["2","1"]).should eql([@connection2,@connection3])
167
+ end
168
+
169
+ context "on :to and :except" do
170
+ context "should value 'except' more that 'to'" do
171
+ it "on :client" do
172
+ self.class.find(:to => {:clients => "client1"},:except => {:clients => "client1"}).should eql([])
173
+ end
174
+ it "on :channels" do
175
+ self.class.find(:to => {:channels => "5"},:except => {:channels => "5"}).should eql([])
176
+ end
177
+ it "on :client allow and :channels except" do
178
+ self.class.find(:to => {:clients => "client2"},:except => {:channels => ["2","5"]}).should eql([])
179
+ end
180
+ it "on :channels allow and :clients except" do
181
+ self.class.find(:to => {:channels => ["5"]},:except => {:clients => "client2"}).should eql([@connection2,@connection4])
182
+ end
79
183
  end
80
184
  end
81
185
  end
82
- it "#find_by_clients should call #find with clients option" do
83
- self.class.should_receive(:find).with({:clients => "client1"})
84
- self.class.find_by_clients("client1")
85
- end
86
- it "#find_by_channels should call #find with channels option" do
87
- self.class.should_receive(:find).with({:channels => "1"})
88
- self.class.find_by_channels("1")
89
- end
90
- it "#find_by_clients_and_channels should call #find with both clients and channels option" do
91
- self.class.should_receive(:find).with({:clients => "client1", :channels => "1"})
92
- self.class.find_by_clients_and_channels("client1","1")
93
- end
94
186
 
95
187
  end
96
188
  end
@@ -55,9 +55,9 @@ describe Socky::Connection do
55
55
  @connection.channels.should_not be_nil
56
56
  @connection.channels.class.should eql(Array)
57
57
  end
58
- it "should return empty table if socket request data 'channels' is nil" do
58
+ it "should return table with nil if socket request data 'channels' is nil" do
59
59
  @connection.socket.request["Query"]["channels"] = nil
60
- @connection.channels.should eql([])
60
+ @connection.channels.should eql([nil])
61
61
  end
62
62
  it "should return table of channels if provided and separated by comma" do
63
63
  @connection.socket.request["Query"]["channels"] = "aaa,bbb,ccc"
@@ -75,87 +75,18 @@ describe Socky::Message do
75
75
  end
76
76
  end
77
77
  context "#broadcast" do
78
- it "should call #broadcast_to_clients if message type is :to_clients" do
79
- @message.stub!(:params).and_return({:type => :to_clients})
80
- @message.stub!(:broadcast_to_clients)
81
- @message.should_receive(:broadcast_to_clients)
78
+ it "should select target connections basing on params" do
79
+ @message.stub!(:params).and_return({:some => :abstract})
80
+ @message.stub!(:send_message)
81
+ Socky::Connection.should_receive(:find).with({:some => :abstract})
82
82
  @message.broadcast
83
83
  end
84
- it "should not distinguish between string and symbol in type" do
85
- @message.stub!(:params).and_return({:type => 'to_clients'})
86
- @message.stub!(:broadcast_to_clients)
87
- @message.should_receive(:broadcast_to_clients)
88
- @message.broadcast
89
- end
90
- it "should call #broadcast_to_channels if message type is :to_channels" do
91
- @message.stub!(:params).and_return({:type => :to_channels})
92
- @message.stub!(:broadcast_to_channels)
93
- @message.should_receive(:broadcast_to_channels)
84
+ it "should call #send_message with message body and connection list" do
85
+ @message.stub!(:params).and_return({:body => "some message"})
86
+ Socky::Connection.stub!(:find).and_return(["first","second"])
87
+ @message.should_receive(:send_message).with("some message", ["first", "second"])
94
88
  @message.broadcast
95
89
  end
96
- it "should call #broadcast_to_clients_on_channels if message type is :to_clients_on_channels" do
97
- @message.stub!(:params).and_return({:type => :to_clients_on_channels})
98
- @message.stub!(:broadcast_to_clients_on_channels)
99
- @message.should_receive(:broadcast_to_clients_on_channels)
100
- @message.broadcast
101
- end
102
- it "should raise error if message type is nil" do
103
- @message.stub!(:params).and_return({:type => nil})
104
- lambda {@message.broadcast}.should raise_error Socky::SockyError
105
- end
106
- it "should raise error if message type is not one of :to_clients, :to_channels or :to_cleints_on_channels" do
107
- @message.stub!(:params).and_return({:type => "invalid"})
108
- lambda {@message.broadcast}.should raise_error Socky::SockyError
109
- end
110
- end
111
- context "#broadcast_to_clients" do
112
- before(:each) do
113
- @message.stub!(:verify)
114
- Socky::Server.stub!(:send_to_clients)
115
- end
116
- it "should verify :clients params existence" do
117
- @message.should_receive(:verify).with(:clients)
118
- @message.broadcast_to_clients
119
- end
120
- it "should call socky server #send_to_clients with own params" do
121
- @message.stub!(:params).and_return(:body => "some message", :clients => "some clients")
122
- Socky::Server.should_receive(:send_to_clients).with("some message", "some clients")
123
- @message.broadcast_to_clients
124
- end
125
- end
126
- context "#broadcast_to_channels" do
127
- before(:each) do
128
- @message.stub!(:verify)
129
- Socky::Server.stub!(:send_to_channels)
130
- end
131
- it "should verify :channels params existence" do
132
- @message.should_receive(:verify).with(:channels)
133
- @message.broadcast_to_channels
134
- end
135
- it "should call socky server #send_to_channels with own params" do
136
- @message.stub!(:params).and_return(:body => "some message", :channels => "some channels")
137
- Socky::Server.should_receive(:send_to_channels).with("some message", "some channels")
138
- @message.broadcast_to_channels
139
- end
140
- end
141
- context "#broadcast_to_clients_on_channels" do
142
- before(:each) do
143
- @message.stub!(:verify)
144
- Socky::Server.stub!(:send_to_clients_on_channels)
145
- end
146
- it "should verify :clients params existence" do
147
- @message.should_receive(:verify).with(:clients)
148
- @message.broadcast_to_clients_on_channels
149
- end
150
- it "should verify :channels params existence" do
151
- @message.should_receive(:verify).with(:channels)
152
- @message.broadcast_to_clients_on_channels
153
- end
154
- it "should call socky server #send_to_clients_on_channels with own params" do
155
- @message.stub!(:params).and_return(:body => "some message", :clients => "some clients", :channels => "some channels")
156
- Socky::Server.should_receive(:send_to_clients_on_channels).with("some message", "some clients", "some channels")
157
- @message.broadcast_to_clients_on_channels
158
- end
159
90
  end
160
91
  context "#query" do
161
92
  it "should call #query_show_connections if message type is :show_connections" do
@@ -193,28 +124,6 @@ describe Socky::Message do
193
124
  @message.query_show_connections
194
125
  end
195
126
  end
196
- context "#verify" do
197
- it "should convert posted field to empty array if field is nil" do
198
- @message.params[:clients] = nil
199
- @message.verify :clients
200
- @message.params[:clients].should eql([])
201
- end
202
- it "should convert posted field to array containing field value if field is not array" do
203
- @message.params[:clients] = "some client"
204
- @message.verify :clients
205
- @message.params[:clients].should eql(["some client"])
206
- end
207
- it "should not convert field if field is array" do
208
- @message.params[:clients] = ["some client"]
209
- @message.verify :clients
210
- @message.params[:clients].should eql(["some client"])
211
- end
212
- it "should change every array value to string" do
213
- @message.params[:clients] = [1,2,3]
214
- @message.verify :clients
215
- @message.params[:clients].should eql(["1","2","3"])
216
- end
217
- end
218
127
  context "#respond" do
219
128
  it "should call creator #send_message" do
220
129
  @connection.should_receive(:send_message)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socky
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 9
9
- version: 0.0.9
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Bernard Potocki
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-20 00:00:00 +02:00
18
+ date: 2010-08-03 00:00:00 +02:00
18
19
  default_executable: socky
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: em-websocket
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 31
27
30
  segments:
28
31
  - 0
29
32
  - 1
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: em-http-request
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 3
41
46
  segments:
42
47
  - 0
43
48
  version: "0"
@@ -69,7 +74,6 @@ files:
69
74
  - lib/socky/options/config.rb
70
75
  - lib/socky/options/parser.rb
71
76
  - lib/socky/runner.rb
72
- - lib/socky/server.rb
73
77
  - spec/em-websocket_spec.rb
74
78
  - spec/files/default.yml
75
79
  - spec/files/invalid.yml
@@ -83,7 +87,6 @@ files:
83
87
  - spec/socky/options/parser_spec.rb
84
88
  - spec/socky/options_spec.rb
85
89
  - spec/socky/runner_spec.rb
86
- - spec/socky/server_spec.rb
87
90
  - spec/socky_spec.rb
88
91
  - spec/spec_helper.rb
89
92
  - spec/stallion.rb
@@ -97,23 +100,27 @@ rdoc_options:
97
100
  require_paths:
98
101
  - lib
99
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
100
104
  requirements:
101
105
  - - ">="
102
106
  - !ruby/object:Gem::Version
107
+ hash: 3
103
108
  segments:
104
109
  - 0
105
110
  version: "0"
106
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
107
113
  requirements:
108
114
  - - ">="
109
115
  - !ruby/object:Gem::Version
116
+ hash: 3
110
117
  segments:
111
118
  - 0
112
119
  version: "0"
113
120
  requirements: []
114
121
 
115
122
  rubyforge_project:
116
- rubygems_version: 1.3.6
123
+ rubygems_version: 1.3.7
117
124
  signing_key:
118
125
  specification_version: 3
119
126
  summary: Socky is a WebSocket server and client for Ruby on Rails
@@ -129,7 +136,6 @@ test_files:
129
136
  - spec/socky/options/parser_spec.rb
130
137
  - spec/socky/options_spec.rb
131
138
  - spec/socky/runner_spec.rb
132
- - spec/socky/server_spec.rb
133
139
  - spec/socky_spec.rb
134
140
  - spec/spec_helper.rb
135
141
  - spec/stallion.rb
@@ -1,28 +0,0 @@
1
- module Socky
2
- class Server
3
- include Socky::Misc
4
-
5
- class << self
6
-
7
- def send_to_clients(message, clients)
8
- connections = Socky::Connection.find_by_clients(clients)
9
- send_data(message, connections)
10
- end
11
-
12
- def send_to_channels(message, channels)
13
- connections = Socky::Connection.find_by_channels(channels)
14
- send_data(message, connections)
15
- end
16
-
17
- def send_to_clients_on_channels(message, clients, channels)
18
- connections = Socky::Connection.find_by_clients_and_channels(clients, channels)
19
- send_data(message, connections)
20
- end
21
-
22
- def send_data(message, connections)
23
- connections.each{|connection| connection.send_message message}
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,35 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe Socky::Server do
4
-
5
- context "class" do
6
- it "#send_data should call send_message on each of provided connections" do
7
- connections = []
8
- 3.times {|i| connections << mock("connection#{i}", :send_message => nil)}
9
- connections.each{|connection| connection.should_receive(:send_message).with("abstract")}
10
- described_class.send_data("abstract",connections)
11
- end
12
- it "#send_to_clients should find connections by clients and call #send_data on them" do
13
- Socky::Connection.stub!(:find_by_clients).and_return(["first","second","third"])
14
- described_class.stub!(:send_data)
15
- Socky::Connection.should_receive(:find_by_clients).with("abstract")
16
- described_class.should_receive(:send_data).with("message", ["first","second","third"])
17
- described_class.send_to_clients("message","abstract")
18
- end
19
- it "#send_to_channels should find connections by channels and call #send_data on them" do
20
- Socky::Connection.stub!(:find_by_channels).and_return(["first","second","third"])
21
- described_class.stub!(:send_data)
22
- Socky::Connection.should_receive(:find_by_channels).with("abstract")
23
- described_class.should_receive(:send_data).with("message", ["first","second","third"])
24
- described_class.send_to_channels("message","abstract")
25
- end
26
- it "#send_to_clients_on_channels should find connections by clients and channels and call #send_data on them" do
27
- Socky::Connection.stub!(:find_by_clients_and_channels).and_return(["first","second","third"])
28
- described_class.stub!(:send_data)
29
- Socky::Connection.should_receive(:find_by_clients_and_channels).with("abstract1","abstract2")
30
- described_class.should_receive(:send_data).with("message", ["first","second","third"])
31
- described_class.send_to_clients_on_channels("message","abstract1","abstract2")
32
- end
33
- end
34
-
35
- end