sinatra-websocket 0.2.1 → 0.3.0

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.3.0
2
+ - [#6](https://github.com/simulacre/sinatra-websocket/pull/6): check for the existence of async.orig_callback - [@crazed](https://github.com/crazed)
3
+
1
4
  ## 0.2.1
2
5
  - [#3](https://github.com/simulacre/sinatra-websocket/pull/3): Lock em-websocket dependency due to latest API changes. - [@pedrocarrico](https://github.com/pedrocarrico)
3
6
 
@@ -1,5 +1,6 @@
1
1
  require 'thin'
2
2
  require 'em-websocket'
3
+ require 'sinatra-websocket/error'
3
4
  require 'sinatra-websocket/ext/thin/connection'
4
5
  require 'sinatra-websocket/ext/sinatra/request'
5
6
 
@@ -7,7 +8,14 @@ module SinatraWebsocket
7
8
  class Connection < ::EventMachine::WebSocket::Connection
8
9
  class << self
9
10
  def from_env(env, options = {})
10
- socket = env[Thin::Request::ASYNC_CALLBACK].receiver
11
+ if env.include?('async.orig_callback')
12
+ callback_key = 'async.orig_callback'
13
+ elsif env.include?(Thin::Request::ASYNC_CALLBACK)
14
+ callback_key = Thin::Request::ASYNC_CALLBACK
15
+ else
16
+ raise Error::ConfigurationError.new('Could not find an async callback in our environment!')
17
+ end
18
+ socket = env[callback_key].receiver
11
19
  request = request_from_env(env)
12
20
  connection = Connection.new(env, socket, :debug => options[:debug])
13
21
  yield(connection) if block_given?
@@ -0,0 +1,9 @@
1
+ module SinatraWebsocket
2
+ module Error
3
+ class StandardError < ::StandardError
4
+ include Error
5
+ end
6
+ class ConfigurationError < StandardError; end
7
+ class ConnectionError < StandardError; end
8
+ end
9
+ end # module::SinatraWebsocket
@@ -13,7 +13,7 @@ module SinatraWebsocket
13
13
  # Taken from skinny https://github.com/sj26/skinny
14
14
  def websocket(options={}, &blk)
15
15
  env['skinny.websocket'] ||= begin
16
- raise RuntimeError, "Not a WebSocket request" unless websocket?
16
+ raise Error::ConnectionError.new("Not a WebSocket request") unless websocket?
17
17
  SinatraWebsocket::Connection.from_env(env, options, &blk)
18
18
  end
19
19
  end
@@ -1,4 +1,4 @@
1
1
  module SinatraWebsocket
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -65,6 +65,7 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
+ - lib/sinatra-websocket/error.rb
68
69
  - lib/sinatra-websocket/ext/sinatra/request.rb
69
70
  - lib/sinatra-websocket/ext/thin/connection.rb
70
71
  - lib/sinatra-websocket/version.rb