Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Apr 4, 2013
2 parents 5fe2398 + 795a11a commit cc6c6db
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,7 @@ language: ruby
rvm:
- 1.9.2
- 1.9.3
- 2.0.0
- rbx-19mode
- jruby-19mode
- ruby-head
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# develop

# 1.1.0
* Feature: Allow specifying an event mask (other than 'ALL') when connecting
* CS: Minor performance improvements from removing repeated regex compilation

# 1.0.5
* Bugfix: Allow sending large app arguments. Application arguments (headers in general) are limited to 2048 bytes. The work-around is to send them in the body of the message with a content-length header.
* CS: Avoid Celluloid deprecation warnings
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_fs/event.rb
Expand Up @@ -3,7 +3,7 @@
module RubyFS
class Event < Response
#
# @return [String[ The name of the event
# @return [String] The name of the event
def event_name
content[:event_name]
end
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_fs/lexer.rb
@@ -1,8 +1,7 @@
module RubyFS
class Lexer
ContentLengthPattern = /Content-length:\s*(\d+)/i
MaxLineLength = 16 * 1024
MaxBinaryLength = 32 * 1024 * 1024
HeaderFormatPattern = /\A([^\s:]+)\s*:\s*/

def initialize(callback)
@callback = callback
Expand Down Expand Up @@ -137,9 +136,9 @@ def set_binary_mode(size = nil)
def headers_2_hash(headers)
{}.tap do |hash|
headers.each do |h|
if /\A([^\s:]+)\s*:\s*/ =~ h
if HeaderFormatPattern =~ h
tail = $'.dup
hash[$1.downcase.gsub(/-/, "_").intern] = tail
hash[$1.downcase.gsub('-', "_").intern] = tail
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/ruby_fs/stream.rb
Expand Up @@ -168,7 +168,7 @@ def receive_request(headers, content)
@command_callbacks.pop.call CommandReply.new(headers, (content == '' ? nil : content))
when 'auth/request'
command "auth #{@secret}" do
async.command "event json ALL" if @events
async.command "event json #{event_mask}" if @events
end
when 'text/disconnect-notice'
terminate
Expand All @@ -181,7 +181,7 @@ def json_content_2_hash(content)
json = JSON.parse content
{}.tap do |hash|
json.each_pair do |k, v|
hash[k.downcase.gsub(/-/,"_").intern] = v
hash[k.downcase.gsub('-',"_").intern] = v
end
end
end
Expand All @@ -190,5 +190,11 @@ def post_init
@state = :started
fire_event Connected.new
end

def event_mask
return 'ALL' if @events == true

Array(@events).join(' ')
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby_fs/version.rb
@@ -1,3 +1,3 @@
module RubyFS
VERSION = "1.0.5"
VERSION = "1.1.0"
end
64 changes: 63 additions & 1 deletion spec/ruby_fs/stream_spec.rb
Expand Up @@ -301,7 +301,7 @@ def expect_disconnected_event
end

context 'with events turned off' do
it 'does not the event mask after authenticating' do
it 'does not set the event mask after authenticating' do
mocked_server(1, lambda { |server| server.send_data "Content-Type: auth/request\n\n" }) do |val, server|
val.should == "auth ClueCon\n\n"
server.send_data %Q(
Expand All @@ -318,6 +318,68 @@ def expect_disconnected_event
end
end

context 'with an event mask fully specified as a string' do
let(:events) { 'CODEC CHANNEL_STATE' }

it 'sets the event mask after authenticating' do
mocked_server(2, lambda { |server| server.send_data "Content-Type: auth/request\n\n" }) do |val, server|
case @sequence
when 1
val.should == "auth ClueCon\n\n"
server.send_data %Q(
Content-Type: command/reply
Reply-Text: +OK accepted
)
when 2
val.should == "event json CODEC CHANNEL_STATE\n\n"
server.send_data %Q(
Content-Type: command/reply
Reply-Text: +OK accepted
)
end
@sequence += 1
end

client_messages.should be == [
Stream::Connected.new,
Stream::Disconnected.new
]
end
end

context 'with an event mask fully specified as an array' do
let(:events) { ['CODEC', 'CHANNEL_STATE'] }

it 'sets the event mask after authenticating' do
mocked_server(2, lambda { |server| server.send_data "Content-Type: auth/request\n\n" }) do |val, server|
case @sequence
when 1
val.should == "auth ClueCon\n\n"
server.send_data %Q(
Content-Type: command/reply
Reply-Text: +OK accepted
)
when 2
val.should == "event json CODEC CHANNEL_STATE\n\n"
server.send_data %Q(
Content-Type: command/reply
Reply-Text: +OK accepted
)
end
@sequence += 1
end

client_messages.should be == [
Stream::Connected.new,
Stream::Disconnected.new
]
end
end

context 'when receiving a disconnect notice' do
it 'puts itself in the stopped state and fires a disconnected event' do
expect_connected_event
Expand Down

0 comments on commit cc6c6db

Please sign in to comment.