rjr 0.16.1 → 0.16.2

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/Rakefile CHANGED
@@ -3,11 +3,8 @@
3
3
  # Copyright (C) 2010-2012 Mohammed Morsi <mo@morsi.org>
4
4
  # Licensed under the Apache License, Version 2.0
5
5
 
6
- require "yard"
7
6
  require "rspec/core/rake_task"
8
7
 
9
- # TODO CI - jenkins/travis/other (also test rjr on jruby)
10
-
11
8
  desc "Run all specs"
12
9
  RSpec::Core::RakeTask.new(:spec) do |spec|
13
10
  spec.pattern = 'specs/**/*_spec.rb'
@@ -28,12 +25,15 @@ task :integration do
28
25
  system("tests/integration/runner")
29
26
  end
30
27
 
31
- YARD::Rake::YardocTask.new do |t|
32
- #t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
33
- #t.options = ['--any', '--extra', '--opts'] # optional
28
+ begin
29
+ require "yard"
30
+ YARD::Rake::YardocTask.new do |t|
31
+ #t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
32
+ #t.options = ['--any', '--extra', '--opts'] # optional
33
+ end
34
+ rescue LoadError
34
35
  end
35
36
 
36
-
37
37
  desc "build the rjr gem"
38
38
  task :build do
39
39
  system "gem build rjr.gemspec"
data/lib/rjr/message.rb CHANGED
@@ -295,12 +295,12 @@ class MessageUtil
295
295
  def self.retrieve_json(data)
296
296
  return nil if data.nil? || data.empty?
297
297
  start = 0
298
- start += 1 until start == data.length || data[start] == '{'
298
+ start += 1 until start == data.length || data[start].chr == '{'
299
299
  on = mi = 0
300
300
  start.upto(data.length - 1).each { |i|
301
- if data[i] == '{'
301
+ if data[i].chr == '{'
302
302
  on += 1
303
- elsif data[i] == '}'
303
+ elsif data[i].chr == '}'
304
304
  on -= 1
305
305
  end
306
306
 
@@ -37,11 +37,9 @@ module Nodes
37
37
  # # => sent via amqp
38
38
  #
39
39
  class Easy < RJR::Node
40
- private
41
-
42
- # Internal helper, retrieved the registered node type depending on
43
- # the dst. If matching node type can't be found, nil is returned
44
- def get_node(dst)
40
+ # Publically available helper, retrieve the rjr node type
41
+ # based on dst format
42
+ def self.node_type_for(dst)
45
43
  type = nil
46
44
  if dst.is_a?(String)
47
45
  if /tcp:\/\/.*/ =~ dst ||
@@ -64,7 +62,21 @@ class Easy < RJR::Node
64
62
  end
65
63
  end
66
64
 
65
+ type
66
+ end
67
+
68
+ private
69
+
70
+ # Internal helper, retrieved the registered node depending on
71
+ # the type retrieved from the dst. If matching node type can't
72
+ # be found, nil is returned
73
+ def get_node(dst)
74
+ type = self.class.node_type_for(dst)
75
+
76
+ # TODO also add optional mechanism to class to load nodes of
77
+ # new types on the fly as they are needed
67
78
  return @multi_node.nodes.find { |n| n.is_a?(type) } unless type.nil?
79
+
68
80
  nil
69
81
  end
70
82
 
@@ -79,7 +91,7 @@ class Easy < RJR::Node
79
91
  def initialize(args = {})
80
92
  super(args)
81
93
 
82
- nodes = []
94
+ nodes = args[:nodes] || []
83
95
  args.keys.each { |n|
84
96
  node =
85
97
  case n
data/lib/rjr/nodes/web.rb CHANGED
@@ -42,6 +42,7 @@ class WebConnection < EventMachine::Connection
42
42
  #
43
43
  # specify the web node establishing the connection
44
44
  def initialize(args = {})
45
+ super
45
46
  @rjr_node = args[:rjr_node]
46
47
  end
47
48
 
@@ -115,12 +116,14 @@ class Web < RJR::Node
115
116
  # are not persistant, we should be sending a
116
117
  # response message here
117
118
 
118
- resp = EventMachine::DelegatedHttpResponse.new(connection)
119
- #resp.status = response.result.success ? 200 : 500
120
- resp.status = 200
121
- resp.content = data.to_s
122
- resp.content_type "application/json"
123
- resp.send_response
119
+ @@em.schedule do
120
+ resp = EventMachine::DelegatedHttpResponse.new(connection)
121
+ #resp.status = response.result.success ? 200 : 500
122
+ resp.status = 200
123
+ resp.content = data.to_s
124
+ resp.content_type "application/json"
125
+ resp.send_response
126
+ end
124
127
  end
125
128
 
126
129
  # Instruct Node to start listening for and dispatching rpc requests
@@ -154,7 +157,8 @@ class Web < RJR::Node
154
157
  }
155
158
 
156
159
  @@em.schedule do
157
- http = EventMachine::HttpRequest.new(uri).post :body => message.to_s
160
+ http = EventMachine::HttpRequest.new(uri).post :body => message.to_s,
161
+ :head => {'content-type' => 'application/json'}
158
162
  http.errback &cb
159
163
  http.callback &cb
160
164
  end
@@ -187,7 +191,8 @@ class Web < RJR::Node
187
191
  :headers => @message_headers
188
192
  cb = lambda { |arg| published_l.synchronize { invoked = true ; published_c.signal }}
189
193
  @@em.schedule do
190
- http = EventMachine::HttpRequest.new(uri).post :body => message.to_s
194
+ http = EventMachine::HttpRequest.new(uri).post :body => message.to_s,
195
+ :head => {'content-type' => 'application/json'}
191
196
  http.errback &cb
192
197
  http.callback &cb
193
198
  end
@@ -43,7 +43,15 @@ module RJR
43
43
  invoked = true
44
44
  m.synchronize { c.signal }
45
45
  }
46
- m.synchronize { c.wait m, 0.5 } if !invoked
46
+ if !invoked
47
+ if RUBY_VERSION < "1.9"
48
+ # XXX ruby 1.8 didn't support timeout via cv.wait
49
+ Thread.new { sleep 0.5 ; c.signal }
50
+ m.synchronize { c.wait m }
51
+ else
52
+ m.synchronize { c.wait m, 0.5 }
53
+ end
54
+ end
47
55
  invoked.should be_true
48
56
  end
49
57
 
data/specs/node_spec.rb CHANGED
@@ -3,6 +3,12 @@ require 'rjr/node'
3
3
 
4
4
  module RJR
5
5
  describe Node do
6
+ before(:all) do
7
+ # was made public in ruby 1.9
8
+ if RUBY_VERSION < "1.9"
9
+ RJR::Node.public_class_method(:class_variable_get)
10
+ end
11
+ end
6
12
 
7
13
  it "should initialize properly from params" do
8
14
  d = Dispatcher.new
@@ -5,6 +5,8 @@ if RJR::Nodes::AMQP == RJR::Nodes::Missing
5
5
  puts "Missing AMQP node dependencies, skipping amqp tests"
6
6
 
7
7
  else
8
+ # TODO stub out calls to external rabbitmq server
9
+
8
10
  module RJR::Nodes
9
11
  describe AMQP do
10
12
  describe "#send_msg" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
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-09-13 00:00:00.000000000 Z
12
+ date: 2013-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.0.1
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.0.1
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: json
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,8 @@ files:
120
120
  - bin/rjr-client
121
121
  - bin/rjr-client-launcher
122
122
  homepage: http://github.com/movitto/rjr
123
- licenses: []
123
+ licenses:
124
+ - Apache 2.0
124
125
  post_install_message:
125
126
  rdoc_options: []
126
127
  require_paths: