julien51-babylon 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ begin
12
12
  gem.requirements = ["eventmachine", "yaml", "fileutils", "log4r", "nokogiri"]
13
13
  gem.executables = "babylon"
14
14
  gem.files = ["bin/babylon", "lib/babylon.rb", "lib/babylon/base/controller.rb", "lib/babylon/base/view.rb", "lib/babylon/client_connection.rb", "lib/babylon/component_connection.rb", "lib/babylon/router/dsl.rb", "lib/babylon/router.rb", "lib/babylon/runner.rb", "lib/babylon/xmpp_connection.rb", "lib/babylon/xmpp_parser.rb", "lib/babylon/xpath_helper.rb", "LICENSE", "Rakefile", "README.rdoc", "templates/babylon/app/controllers/README.rdoc", "templates/babylon/app/models/README.rdoc", "templates/babylon/app/views/README.rdoc", "templates/babylon/config/boot.rb", "templates/babylon/config/config.yaml", "templates/babylon/config/dependencies.rb", "templates/babylon/config/routes.rb", "templates/babylon/config/initializers/README.rdoc"]
15
+ gem.rubyforge_project = 'babylon' # This line would be new
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
17
18
  rescue LoadError
@@ -34,18 +35,18 @@ Rake::TestTask.new(:test) do |test|
34
35
  test.verbose = false
35
36
  end
36
37
 
37
- # begin
38
- # require 'rcov/rcovtask'
39
- # Rcov::RcovTask.new do |test|
40
- # test.libs << 'test'
41
- # test.pattern = 'test/**/*_test.rb'
42
- # test.verbose = true
43
- # end
44
- # rescue LoadError
45
- # task :rcov do
46
- # abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
- # end
48
- # end
38
+ begin
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/*_test.rb'
43
+ test.verbose = true
44
+ end
45
+ rescue LoadError
46
+ task :rcov do
47
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
48
+ end
49
+ end
49
50
 
50
51
  begin
51
52
  require 'spec/rake/spectask'
@@ -53,26 +54,57 @@ begin
53
54
  Spec::Rake::SpecTask.new('spec') do |spec|
54
55
  spec.spec_files = FileList['spec/**/*.rb']
55
56
  spec.verbose = true
57
+ spec.warning = true
58
+ spec.rcov = true
59
+ spec.rcov_opts = []
60
+ spec.rcov_opts = ['--exclude', 'spec']
56
61
  end
57
62
  rescue LoadError
58
- task :rcov do
63
+ task :spec do
59
64
  abort "Rspec is not available. In order to run rspec, you must: sudo gem install rspec"
60
65
  end
61
66
  end
62
67
 
63
68
  begin
64
- require 'rcov/rcovtask'
65
- Rcov::RcovTask.new do |test|
66
- test.libs << 'spec'
67
- test.pattern = 'spec/**/*_spec.rb'
68
- test.verbose = true
69
+ require 'spec/rake/verify_rcov'
70
+
71
+ RCov::VerifyTask.new(:verify_rcov => 'spec') do |t|
72
+ t.threshold = 100.0
73
+ t.index_html = 'coverage/index.html'
69
74
  end
70
75
  rescue LoadError
71
- task :rcov do
72
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
76
+ task :spec do
77
+ abort "Rcov is not available. In order to run rcov, you must: sudo gem install rcov"
73
78
  end
74
79
  end
75
80
 
81
+ # These are Rubyforge tasks
82
+ begin
83
+ require 'rake/contrib/sshpublisher'
84
+ namespace :rubyforge do
85
+
86
+ desc "Release gem and RDoc documentation to RubyForge"
87
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
88
+
89
+ namespace :release do
90
+ desc "Publish RDoc to RubyForge."
91
+ task :docs => [:rdoc] do
92
+ config = YAML.load(
93
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
94
+ )
95
+
96
+ host = "#{config['username']}@rubyforge.org"
97
+ remote_dir = "/var/www/gforge-projects/babylon"
98
+ local_dir = 'rdoc'
99
+
100
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
101
+ end
102
+ end
103
+ end
104
+ rescue LoadError
105
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
106
+ end
107
+
76
108
 
77
109
  task :install => :build
78
110
 
@@ -49,7 +49,7 @@ module Babylon
49
49
  end
50
50
  }
51
51
  rescue NameError
52
- Babylon.logger.debug "Resolv::DNS does not support SRV records. Please upgrade to ruby-1.8.3 or later! \n #{$!} : #{$!.inspect}"
52
+ Babylon.logger.debug "Resolv::DNS does not support SRV records. Please upgrade to ruby-1.8.3 or later! \n#{$!} : #{$!.backtrace.join("\n")}"
53
53
  end
54
54
  end
55
55
  end
@@ -165,7 +165,11 @@ module Babylon
165
165
  # And now, send a presence!
166
166
  presence = Nokogiri::XML::Node.new("presence", @outstream)
167
167
  send(presence)
168
- @handler.on_connected(self) if @handler
168
+ begin
169
+ @handler.on_connected(self) if @handler and @handler.respond_to?("on_connected")
170
+ rescue
171
+ Babylon.logger.error("on_connected failed : #{$!}\n#{$!.backtrace.join("\n")}")
172
+ end
169
173
  @state = :connected
170
174
  end
171
175
 
@@ -47,7 +47,11 @@ module Babylon
47
47
 
48
48
  when :wait_for_handshake
49
49
  if stanza.name == "handshake"
50
- @handler.on_connected(self) if @handler
50
+ begin
51
+ @handler.on_connected(self) if @handler and @handler.respond_to?("on_connected")
52
+ rescue
53
+ Babylon.logger.error("on_connected failed : #{$!}\n#{$!.backtrace.join("\n")}")
54
+ end
51
55
  @state = :connected
52
56
  elsif stanza.name == "stream:error"
53
57
  raise AuthenticationError
@@ -51,20 +51,20 @@ module Babylon
51
51
 
52
52
  ##
53
53
  # Will be called by the connection class once it is connected to the server.
54
- def on_connected(connection)
55
- Babylon::CentralRouter.method(:connected)
54
+ def self.on_connected(connection)
55
+ Babylon::CentralRouter.connected(connection)
56
56
  end
57
57
 
58
58
  ##
59
59
  # Will be called by the connection class upon disconnection.
60
- def on_disconnected()
60
+ def self.on_disconnected()
61
61
  EventMachine.stop_event_loop
62
62
  end
63
63
 
64
64
  ##
65
65
  # Will be called by the connection class when it receives and parses a stanza.
66
- def on_stanza(stanza)
67
- Babylon::CentralRouter.method(:route)
66
+ def self.on_stanza(stanza)
67
+ Babylon::CentralRouter.route(stanza)
68
68
  end
69
69
 
70
70
  end
@@ -7,17 +7,17 @@ module Babylon
7
7
  ##
8
8
  # xml-not-well-formed Exception
9
9
  class XmlNotWellFormed < Exception; end
10
-
10
+
11
11
  ##
12
12
  # Authentication Error (wrong password/jid combination). Used for Clients and Components
13
13
  class AuthenticationError < Exception; end
14
-
14
+
15
15
  ##
16
16
  # This class is in charge of handling the network connection to the XMPP server.
17
17
  class XmppConnection < EventMachine::Connection
18
-
18
+
19
19
  attr_accessor :jid, :host, :port
20
-
20
+
21
21
  ##
22
22
  # Connects the XmppConnection to the right host with the right port. I
23
23
  # It passes itself (as handler) and the configuration
@@ -26,22 +26,29 @@ module Babylon
26
26
  Babylon.logger.debug("CONNECTING TO #{params["host"]}:#{params["port"]}") # Very low level Logging
27
27
  EventMachine.connect(params["host"], params["port"], self, params.merge({"handler" => handler}))
28
28
  end
29
-
29
+
30
30
  def connection_completed
31
+ @connected = true
31
32
  Babylon.logger.debug("CONNECTED") # Very low level Logging
32
33
  end
33
34
 
34
35
  ##
35
36
  # Called when the connection is terminated and stops the event loop
36
37
  def unbind()
38
+ @connected = false
37
39
  Babylon.logger.debug("DISCONNECTED") # Very low level Logging
38
- @handler.on_disconnected(self) if @handler
40
+ begin
41
+ @handler.on_disconnected() if @handler and @handler.respond_to?("on_disconnected")
42
+ rescue
43
+ Babylon.logger.error("on_disconnected failed : #{$!}\n#{$!.backtrace.join("\n")}")
44
+ end
39
45
  end
40
46
 
41
47
  ##
42
48
  # Instantiate the Handler (called internally by EventMachine) and attaches a new XmppParser
43
49
  def initialize(params)
44
50
  super()
51
+ @connected = false
45
52
  @jid = params["jid"]
46
53
  @password = params["password"]
47
54
  @host = params["host"]
@@ -65,14 +72,19 @@ module Babylon
65
72
  # In any case, we need to close the connection.
66
73
  close_connection
67
74
  else
68
- @handler.on_stanza(stanza) if @handler
75
+ begin
76
+ @handler.on_stanza(stanza) if @handler and @handler.respond_to?("on_stanza")
77
+ rescue
78
+ Babylon.logger.error("on_stanza failed : #{$!}\n#{$!.backtrace.join("\n")}")
79
+ end
69
80
  end
70
81
  end
71
-
82
+
72
83
  ##
73
84
  # Sends the Nokogiri::XML data (after converting to string) on the stream. It also appends the right "from" to be the component's JId if none has been mentionned. Eventually it displays this data for debugging purposes.
74
85
  # This method also adds a "from" attribute to all stanza if it was ommited (the full jid) only if a "to" attribute is present. if not, we assume that we're speaking to the server and the server doesn't need a "from" to identify where the message is coming from.
75
86
  def send(xml)
87
+ raise NotConnected unless @connected
76
88
  if xml.is_a? Nokogiri::XML::NodeSet
77
89
  xml.each do |node|
78
90
  send_node(node)
@@ -93,19 +105,27 @@ module Babylon
93
105
  node["from"] ||= jid if node["to"]
94
106
  send_string(node.to_xml)
95
107
  end
96
-
108
+
97
109
  ##
98
110
  # Sends a string on the line
99
111
  def send_string(string)
100
- Babylon.logger.debug("SENDING : #{string}")
101
- send_data("#{string}")
112
+ begin
113
+ Babylon.logger.debug("SENDING : #{string}")
114
+ send_data("#{string}")
115
+ rescue
116
+ Babylon.logger.error("#{$!}\n#{$!.backtrace.join("\n")}")
117
+ end
102
118
  end
103
119
 
104
120
  ##
105
121
  # receive_data is called when data is received. It is then passed to the parser.
106
122
  def receive_data(data)
107
- Babylon.logger.debug("RECEIVED : #{data}")
108
- @parser.push(data)
123
+ begin
124
+ Babylon.logger.debug("RECEIVED : #{data}")
125
+ @parser.push(data)
126
+ rescue
127
+ Babylon.logger.error("#{$!}\n#{$!.backtrace.join("\n")}")
128
+ end
109
129
  end
110
130
  end
111
131
 
@@ -58,13 +58,13 @@ module Babylon
58
58
  # Should be called only for stream:stream.
59
59
  # We re-initialize the document and set its root to be the newly created element.
60
60
  start_document
61
- @doc.root = e
61
+ @doc.root = @root = e
62
62
  # Also, we activate the callback since this element will never end.
63
63
  @callback.call(e)
64
64
  else
65
65
  # Adding the newly created element to the @elem that is being parsed, or, if no element is being parsed, then we set the @top and the @elem to be this newly created element.
66
66
  # @top is the "highest" element to (it's parent is the <stream> element)
67
- @elem = @elem ? @elem.add_child(e) : (@top = @doc.root.add_child(e))
67
+ @elem = @elem ? @elem.add_child(e) : (@top = @root.add_child(e))
68
68
  end
69
69
  end
70
70
 
@@ -75,7 +75,7 @@ module Babylon
75
75
  if @elem == @top
76
76
  @callback.call(@elem)
77
77
  # Remove the element from its content, since we're done with it!
78
- @elem.unlink
78
+ @elem.unlink if @elem
79
79
  # And the current elem is the next sibling or the root
80
80
  @elem = @top = nil
81
81
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-babylon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - julien Genestoux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-25 00:00:00 -07:00
12
+ date: 2009-03-26 00:00:00 -07:00
13
13
  default_executable: babylon
14
14
  dependencies: []
15
15
 
@@ -72,7 +72,7 @@ requirements:
72
72
  - fileutils
73
73
  - log4r
74
74
  - nokogiri
75
- rubyforge_project:
75
+ rubyforge_project: babylon
76
76
  rubygems_version: 1.2.0
77
77
  signing_key:
78
78
  specification_version: 2