socky-server 0.4.1 → 0.5.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/.gitignore +0 -4
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.md +11 -5
  4. data/Gemfile +2 -0
  5. data/README.md +47 -68
  6. data/Rakefile +5 -7
  7. data/config.ru +19 -0
  8. data/example/config.yml +4 -0
  9. data/lib/socky/server.rb +23 -0
  10. data/lib/socky/server/application.rb +51 -0
  11. data/lib/socky/server/channel.rb +30 -0
  12. data/lib/socky/server/channel/base.rb +80 -0
  13. data/lib/socky/server/channel/presence.rb +49 -0
  14. data/lib/socky/server/channel/private.rb +44 -0
  15. data/lib/socky/server/channel/public.rb +43 -0
  16. data/lib/socky/server/channel/stub.rb +17 -0
  17. data/lib/socky/server/config.rb +52 -0
  18. data/lib/socky/server/connection.rb +66 -0
  19. data/lib/socky/server/http.rb +95 -0
  20. data/lib/socky/server/logger.rb +24 -0
  21. data/lib/socky/server/message.rb +35 -0
  22. data/lib/socky/server/misc.rb +18 -0
  23. data/lib/socky/server/version.rb +5 -0
  24. data/lib/socky/server/websocket.rb +43 -0
  25. data/socky-server.gemspec +5 -7
  26. data/spec/fixtures/example_config.yml +3 -0
  27. data/spec/integration/ws_channels_spec.rb +144 -0
  28. data/spec/integration/ws_connection_spec.rb +48 -0
  29. data/spec/integration/ws_presence_spec.rb +118 -0
  30. data/spec/integration/ws_rights_spec.rb +133 -0
  31. data/spec/spec_helper.rb +24 -2
  32. data/spec/support/websocket_application.rb +14 -0
  33. data/spec/unit/socky/server/application_spec.rb +54 -0
  34. data/spec/unit/socky/server/config_spec.rb +50 -0
  35. data/spec/unit/socky/server/connection_spec.rb +67 -0
  36. data/spec/unit/socky/server/message_spec.rb +64 -0
  37. metadata +93 -126
  38. data/bin/socky +0 -5
  39. data/lib/em-websocket_hacks.rb +0 -15
  40. data/lib/socky.rb +0 -75
  41. data/lib/socky/connection.rb +0 -137
  42. data/lib/socky/connection/authentication.rb +0 -99
  43. data/lib/socky/connection/finders.rb +0 -67
  44. data/lib/socky/message.rb +0 -85
  45. data/lib/socky/misc.rb +0 -74
  46. data/lib/socky/net_request.rb +0 -27
  47. data/lib/socky/options.rb +0 -39
  48. data/lib/socky/options/config.rb +0 -79
  49. data/lib/socky/options/parser.rb +0 -93
  50. data/lib/socky/runner.rb +0 -95
  51. data/spec/em-websocket_spec.rb +0 -36
  52. data/spec/files/default.yml +0 -18
  53. data/spec/files/invalid.yml +0 -1
  54. data/spec/socky/connection/authentication_spec.rb +0 -183
  55. data/spec/socky/connection/finders_spec.rb +0 -188
  56. data/spec/socky/connection_spec.rb +0 -151
  57. data/spec/socky/message_spec.rb +0 -102
  58. data/spec/socky/misc_spec.rb +0 -74
  59. data/spec/socky/net_request_spec.rb +0 -42
  60. data/spec/socky/options/config_spec.rb +0 -72
  61. data/spec/socky/options/parser_spec.rb +0 -76
  62. data/spec/socky/options_spec.rb +0 -60
  63. data/spec/socky/runner_spec.rb +0 -88
  64. data/spec/socky_spec.rb +0 -89
  65. data/spec/support/stallion.rb +0 -96
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Socky do
4
-
5
- context "class" do
6
-
7
- it "should have non-blank version" do
8
- Socky::VERSION.should_not be_nil
9
- end
10
- it "should have options in hash form" do
11
- Socky.options.should_not be_nil
12
- Socky.options.class.should eql(Hash)
13
- end
14
- it "should allow to set options" do
15
- Socky.options.should eql(Hash.new)
16
- begin
17
- Socky.options = {:key => :value}
18
- Socky.options.should eql({:key => :value})
19
- ensure
20
- Socky.options = Hash.new
21
- end
22
- end
23
- it "should have logger" do
24
- Socky.logger.should_not be_nil
25
- Socky.logger.class.should eql(Logger)
26
- end
27
- it "should have logger with STDOUT at default" do
28
- Socky.logger.instance_variable_get('@logdev').dev.class.should eql(IO)
29
- end
30
- it "should be able to set logger" do
31
- begin
32
- logger = Logger.new(STDOUT)
33
- Socky.logger.should_not equal(logger)
34
- Socky.logger = logger
35
- Socky.logger.should equal(logger)
36
- ensure
37
- Socky.logger = nil
38
- end
39
- end
40
- it "should be able to change verbosity of logger by setting debug option" do
41
- begin
42
- Socky.logger.level.should eql(Logger::INFO)
43
- Socky.logger = nil
44
- Socky.stub!(:options).and_return({:debug => true})
45
- Socky.logger.level.should eql(Logger::DEBUG)
46
- Socky.logger = nil
47
- Socky.stub!(:options).and_return({:debug => false})
48
- Socky.logger.level.should eql(Logger::INFO)
49
- ensure
50
- Socky.logger = nil
51
- end
52
- end
53
- it "should not have default log path" do
54
- Socky.log_path.should be_nil
55
- end
56
- it "should be able to change log path by settion log_path option" do
57
- Socky.stub!(:options).and_return({:log_path => "abstract"})
58
- Socky.log_path.should eql("abstract")
59
- end
60
- it "should be able to change logger write place" do
61
- begin
62
- Socky.options = {:log_path => File.join(File.dirname(__FILE__), 'files', 'socky.log')}
63
- Socky.logger.should_not be_nil
64
- Socky.logger.instance_variable_get('@logdev').dev.class.should eql(File)
65
- ensure
66
- Socky.logger = nil
67
- Socky.options = {}
68
- end
69
- end
70
- it "should have default pid path" do
71
- Socky.pid_path.should_not be_nil
72
- Socky.pid_path.should eql("/var/run/socky.pid")
73
- end
74
- it "should be able to change pid path by settion pid_path option" do
75
- Socky.stub!(:options).and_return({:pid_path => "abstract"})
76
- Socky.pid_path.should eql("abstract")
77
- end
78
- it "should have default config path" do
79
- Socky.config_path.should_not be_nil
80
- Socky.config_path.should eql("/var/run/socky.yml")
81
- end
82
- it "should be able to change config path by settion config_path option" do
83
- Socky.stub!(:options).and_return({:config_path => "abstract"})
84
- Socky.config_path.should eql("abstract")
85
- end
86
-
87
- end
88
-
89
- end
@@ -1,96 +0,0 @@
1
- # #--
2
- # Includes portion originally Copyright (C)2008 Michael Fellinger
3
- # license See file LICENSE for details
4
- # #--
5
-
6
- require 'rack'
7
-
8
- module Stallion
9
- class Mount
10
- def initialize(name, *methods, &block)
11
- @name, @methods, @block = name, methods, block
12
- end
13
-
14
- def ride
15
- @block.call
16
- end
17
-
18
- def match?(request)
19
- method = request['REQUEST_METHOD']
20
- right_method = @methods.empty? or @methods.include?(method)
21
- end
22
- end
23
-
24
- class Stable
25
- attr_reader :request, :response
26
-
27
- def initialize
28
- @boxes = {}
29
- end
30
-
31
- def in(path, *methods, &block)
32
- mount = Mount.new(path, *methods, &block)
33
- @boxes[[path, methods]] = mount
34
- mount
35
- end
36
-
37
- def call(request, response)
38
- @request, @response = request, response
39
- @boxes.each do |(path, methods), mount|
40
- if mount.match?(request)
41
- mount.ride
42
- end
43
- end
44
- end
45
- end
46
-
47
- STABLES = {}
48
-
49
- def self.saddle(name = nil)
50
- STABLES[name] = stable = Stable.new
51
- yield stable
52
- end
53
-
54
- def self.run(options = {})
55
- options = {:Host => "127.0.0.1", :Port => 8080}.merge(options)
56
- Rack::Handler::Mongrel.run(Rack::Lint.new(self), options)
57
- end
58
-
59
- def self.call(env)
60
- request = Rack::Request.new(env)
61
- response = Rack::Response.new
62
-
63
- STABLES.each do |name, stable|
64
- stable.call(request, response)
65
- end
66
-
67
- response.finish
68
- end
69
- end
70
-
71
- Stallion.saddle :spec do |stable|
72
- stable.in '/' do
73
-
74
- if stable.request.path_info == '/fail'
75
- stable.response.status = 404
76
-
77
- elsif stable.request.path_info == '/timeout'
78
- sleep(10)
79
- stable.response.write 'timeout'
80
-
81
- elsif
82
- stable.response.write 'Hello, World!'
83
- end
84
-
85
- end
86
- end
87
-
88
- Thread.new do
89
- begin
90
- Stallion.run :Host => '127.0.0.1', :Port => 8765
91
- rescue Exception => e
92
- print e
93
- end
94
- end
95
-
96
- sleep(1)