mohiam-babylon 0.1.7

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 (47) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +111 -0
  3. data/Rakefile +145 -0
  4. data/bin/babylon +6 -0
  5. data/lib/babylon.rb +119 -0
  6. data/lib/babylon/base/controller.rb +116 -0
  7. data/lib/babylon/base/stanza.rb +23 -0
  8. data/lib/babylon/base/view.rb +49 -0
  9. data/lib/babylon/client_connection.rb +210 -0
  10. data/lib/babylon/component_connection.rb +87 -0
  11. data/lib/babylon/generator.rb +139 -0
  12. data/lib/babylon/router.rb +103 -0
  13. data/lib/babylon/router/dsl.rb +61 -0
  14. data/lib/babylon/runner.rb +148 -0
  15. data/lib/babylon/xmpp_connection.rb +172 -0
  16. data/lib/babylon/xmpp_parser.rb +111 -0
  17. data/lib/babylon/xpath_helper.rb +13 -0
  18. data/spec/bin/babylon_spec.rb +0 -0
  19. data/spec/em_mock.rb +42 -0
  20. data/spec/lib/babylon/base/controller_spec.rb +205 -0
  21. data/spec/lib/babylon/base/stanza_spec.rb +15 -0
  22. data/spec/lib/babylon/base/view_spec.rb +86 -0
  23. data/spec/lib/babylon/client_connection_spec.rb +304 -0
  24. data/spec/lib/babylon/component_connection_spec.rb +135 -0
  25. data/spec/lib/babylon/generator_spec.rb +10 -0
  26. data/spec/lib/babylon/router/dsl_spec.rb +72 -0
  27. data/spec/lib/babylon/router_spec.rb +189 -0
  28. data/spec/lib/babylon/runner_spec.rb +213 -0
  29. data/spec/lib/babylon/xmpp_connection_spec.rb +197 -0
  30. data/spec/lib/babylon/xmpp_parser_spec.rb +275 -0
  31. data/spec/lib/babylon/xpath_helper_spec.rb +25 -0
  32. data/spec/spec_helper.rb +34 -0
  33. data/templates/babylon/app/controllers/controller.rb +7 -0
  34. data/templates/babylon/app/stanzas/stanza.rb +6 -0
  35. data/templates/babylon/app/views/view.rb +6 -0
  36. data/templates/babylon/config/boot.rb +16 -0
  37. data/templates/babylon/config/config.yaml +24 -0
  38. data/templates/babylon/config/dependencies.rb +1 -0
  39. data/templates/babylon/config/routes.rb +22 -0
  40. data/templates/babylon/log/development.log +0 -0
  41. data/templates/babylon/log/production.log +0 -0
  42. data/templates/babylon/log/test.log +52 -0
  43. data/templates/babylon/script/component +46 -0
  44. data/templates/babylon/tmp/pids/README +2 -0
  45. data/test/babylon_test.rb +7 -0
  46. data/test/test_helper.rb +10 -0
  47. metadata +179 -0
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Babylon::XpathHelper do
4
+ describe "namespace method" do
5
+ before do
6
+ @doc = Nokogiri::XML(<<-eoxml)
7
+ <iq from='me@my.jid/Eee' to='component.my.jid'
8
+ xml:lang='en' type='get' id='43'><query
9
+ xmlns='http://jabber.org/protocol/disco#info'/></iq>
10
+ eoxml
11
+ end
12
+
13
+ it "matches nodes of the given name with the given namespace URI" do
14
+ @doc.xpath("//iq/*[namespace(., 'query', 'http://jabber.org/protocol/disco#info')]", Babylon::XpathHelper.new).length.should == 1
15
+ end
16
+
17
+ it "does not match a namespace URI if the node names differ" do
18
+ @doc.xpath("//iq/*[namespace(., 'que', 'http://jabber.org/protocol/disco#info')]", Babylon::XpathHelper.new).length.should == 0
19
+ end
20
+
21
+ it "does not match a node if the namespace URIs differ" do
22
+ @doc.xpath("//iq/*[namespace(., 'query', 'http://jabber.org/protocol/disco#inf')]", Babylon::XpathHelper.new).length.should == 0
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/../lib/babylon"
2
+
3
+ # #
4
+ # Deactivate the logging
5
+ Babylon.logger.level = Log4r::FATAL
6
+
7
+ Babylon.environment = "test"
8
+
9
+ if !defined? BabylonSpecHelper
10
+ module BabylonSpecHelper
11
+ ##
12
+ # Load configuration from a local config file
13
+ def babylon_config
14
+ @config ||= YAML.load(File.read(File.join(File.dirname(__FILE__), "config.yaml")))
15
+ end
16
+
17
+ ##
18
+ # Mock for Handler
19
+ def handler_mock
20
+ @handler_mock ||=
21
+ begin
22
+ mock(Object, { :on_connected => Proc.new { |conn|
23
+ },
24
+ :on_disconnected => Proc.new {
25
+ # Disconnected
26
+ },
27
+ :on_stanza => Proc.new { |stanza|
28
+ # Stanza!
29
+ }
30
+ })
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ class <%= controller_class_name %> < Babylon::Base::Controller
2
+ <% controller_actions.each do |action, prio, xpath| %>
3
+ def <%= action %>
4
+ # This will be called when a stanza matches <%= xpath %>
5
+ end
6
+ <% end %>
7
+ end
@@ -0,0 +1,6 @@
1
+ class Stanza < Babylon::Base::Stanza
2
+ # element :message, :as => :to, :value => :to (will add a .to method for your <message> stanza, based on the "to" attribute)
3
+ # element :pubsub (will match to the content of <pubsub> and define a .pubsub method)
4
+ # element :publish, :as => :node, :value => :node (will match to the content of the "node" attribute of <publish> and defined a .node method)
5
+ # elements :entry, :as => :entries, :class => AtomEntry (will match <entry> elements to a subclass AtomEntry (that you must define, using SaxMachine) and create a .entries.methods that returns an Array of AtomEntry.
6
+ end
@@ -0,0 +1,6 @@
1
+ # Please see Babylon Rdoc. Put all the views related to controller MyController into app/views/my/...
2
+ # This file are Xml Builder Files (see Nokogiri Documentation for any doubt : http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Builder.html ).
3
+
4
+ # xml.message(:to => @to, :from => @from, :type => :chat) do
5
+ # xml.body(@body) # Same as self.send(:body, body)
6
+ # end
@@ -0,0 +1,16 @@
1
+ ##
2
+ # This file is run by the dameons, in the apps directory
3
+
4
+ # Change directory to the app's directory.
5
+ Dir.chdir(File.dirname(__FILE__) + "/../")
6
+
7
+ require "rubygems"
8
+ require "babylon"
9
+ require File.dirname(__FILE__) + "/dependencies"
10
+
11
+
12
+ # Start the App
13
+ Babylon::Runner::run(ARGV[0] || "development") do
14
+ # Run the initializers, too. This is done here since some initializers might need EventMachine to be started.
15
+ Dir.glob('config/initializers/*.rb').each { |f| require f }
16
+ end
@@ -0,0 +1,24 @@
1
+ # This contains the global configuration of your component.
2
+ # environment:
3
+ # jid: your.component.jid
4
+ # password: your.component.password
5
+ # host: host on which the XMPP server is running
6
+ # port: port to which your component should connect
7
+ # application_type: client | component (by default it is component and we strongly discourage any client application in production)
8
+
9
+ development:
10
+ jid: user@server.com
11
+ password: password
12
+ application_type: client
13
+
14
+ test:
15
+ jid: component.server.com
16
+ password: password
17
+ host: localhost
18
+ port: 5278
19
+
20
+ production:
21
+ jid: component.server.com
22
+ password: password
23
+ host: localhost
24
+ port: 5278
@@ -0,0 +1 @@
1
+ # Require any application-specific dependencies here.
@@ -0,0 +1,22 @@
1
+ # Routes require an xpath against which to match, and a controller/action pair to which to map.
2
+ #
3
+ # xpath("//message[@type = 'chat']").to(:controller => "message", :action => "receive")
4
+ #
5
+ # Routes can be assigned priorities. The highest priority executes first, and the default priority is 0.
6
+ #
7
+ # xpath("//message[@type = 'chat']").to(:controller => "message", :action => "priority").priority(5000000)
8
+ #
9
+ # It is not possible to easily check for namespace URI equivalence in xpath, but the following helper function was added.
10
+ #
11
+ # xpath("//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco#info')]").to(:controller => "discovery", :action => "services")
12
+ #
13
+ # That syntax is ugly out of necessity. But, relax, you're using Ruby.
14
+ #
15
+ # There are a few helper methods for generating xpaths. The following is equivalent to the above example:
16
+ #
17
+ # disco_info.to(:controller => "discovery", :action => "services")
18
+ #
19
+ # See lib/babylon/router/dsl.rb for more helpers.
20
+ Babylon.router.draw do
21
+
22
+ end
File without changes
File without changes
@@ -0,0 +1,52 @@
1
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
2
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
3
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
4
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
5
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
6
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
7
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
8
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
9
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
10
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
11
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
12
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
13
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
14
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
15
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
16
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
17
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
18
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
19
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
20
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
21
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
22
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
23
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
24
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
25
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
26
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
27
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
28
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
29
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
30
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
31
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
32
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
33
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
34
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
35
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
36
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
37
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
38
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
39
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
40
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
41
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
42
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
43
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
44
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
45
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
46
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
47
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
48
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
49
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
50
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
51
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
52
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'daemons'
4
+ require 'optparse'
5
+
6
+ # default options
7
+ command = "run"
8
+ environment = "development"
9
+ name = "#{Dir.pwd.split("/").last}"
10
+
11
+ ARGV.options do |o|
12
+ script_name = File.basename($0)
13
+
14
+ o.set_summary_indent(' ')
15
+ o.banner = "Usage: script/#{script_name} [OPTIONS]"
16
+ o.define_head "Runs the Babylon Application."
17
+ o.separator ""
18
+ o.separator "Arguments :"
19
+
20
+ o.on("-c", "--command=[run|start|stop|restart]", String,
21
+ "The command you'd like to execute",
22
+ "Default: #{command}") { |command| }
23
+ o.on("-e", "--environment=env", String,
24
+ "The environment to run the application (you should have defined the argument into config/config.yaml)",
25
+ "Default: #{environment}") { |environment| }
26
+ o.on("-n", "--name=app_name", String,
27
+ "Name of your application. The pid_file will be name after this.",
28
+ "Default: #{name}") { |name| }
29
+
30
+ o.separator ""
31
+
32
+ o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
33
+
34
+ o.parse!
35
+ end
36
+
37
+
38
+ options = {
39
+ :ARGV => [command, '--', environment],
40
+ :app_name => name,
41
+ :dir => "../tmp/pids/",
42
+ :multiple => false,
43
+ :backtrace => true
44
+ }
45
+ $app_name = options[:app_name]
46
+ Daemons.run(File.dirname(__FILE__) + '/../config/boot.rb', options)
@@ -0,0 +1,2 @@
1
+ # This is the pid directory. Please do not delete.
2
+ # Also, when your application fails, you will find a .log ile here that shows the last trace
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BabylonTest < Test::Unit::TestCase
4
+ # Tests are done through Rspec... but feel free to add any Unit tests you think might be helpful to understand and fix code more easily
5
+ should "probably rename this file and start testing for real" do
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'babylon'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mohiam-babylon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - julien Genestoux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-16 00:00:00 -07:00
13
+ default_executable: babylon
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: log4r
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: eventmachine
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: julien51-sax-machine
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: templater
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: daemons
77
+ type: :runtime
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ description:
86
+ email: julien.genestoux@gmail.com
87
+ executables:
88
+ - babylon
89
+ extensions: []
90
+
91
+ extra_rdoc_files:
92
+ - LICENSE
93
+ - README.rdoc
94
+ files:
95
+ - LICENSE
96
+ - README.rdoc
97
+ - Rakefile
98
+ - bin/babylon
99
+ - lib/babylon.rb
100
+ - lib/babylon/base/controller.rb
101
+ - lib/babylon/base/stanza.rb
102
+ - lib/babylon/base/view.rb
103
+ - lib/babylon/client_connection.rb
104
+ - lib/babylon/component_connection.rb
105
+ - lib/babylon/generator.rb
106
+ - lib/babylon/router.rb
107
+ - lib/babylon/router/dsl.rb
108
+ - lib/babylon/runner.rb
109
+ - lib/babylon/xmpp_connection.rb
110
+ - lib/babylon/xmpp_parser.rb
111
+ - lib/babylon/xpath_helper.rb
112
+ - templates/babylon/app/controllers/controller.rb
113
+ - templates/babylon/app/stanzas/stanza.rb
114
+ - templates/babylon/app/views/view.rb
115
+ - templates/babylon/config/boot.rb
116
+ - templates/babylon/config/config.yaml
117
+ - templates/babylon/config/dependencies.rb
118
+ - templates/babylon/config/routes.rb
119
+ - templates/babylon/log/development.log
120
+ - templates/babylon/log/production.log
121
+ - templates/babylon/log/test.log
122
+ - templates/babylon/script/component
123
+ - templates/babylon/tmp/pids/README
124
+ has_rdoc: true
125
+ homepage: http://github.com/julien51/babylon
126
+ licenses:
127
+ post_install_message:
128
+ rdoc_options:
129
+ - --charset=UTF-8
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: "0"
137
+ version:
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: "0"
143
+ version:
144
+ requirements:
145
+ - eventmachine
146
+ - yaml
147
+ - fileutils
148
+ - log4r
149
+ - nokogiri
150
+ - sax-machine
151
+ - templater
152
+ - daemons
153
+ - optparse
154
+ - digest/sha1
155
+ - base64
156
+ - resolv
157
+ rubyforge_project: babylon
158
+ rubygems_version: 1.3.5
159
+ signing_key:
160
+ specification_version: 2
161
+ summary: Babylon is a framework to create EventMachine based XMPP External Components in Ruby.
162
+ test_files:
163
+ - spec/bin/babylon_spec.rb
164
+ - spec/em_mock.rb
165
+ - spec/lib/babylon/base/controller_spec.rb
166
+ - spec/lib/babylon/base/stanza_spec.rb
167
+ - spec/lib/babylon/base/view_spec.rb
168
+ - spec/lib/babylon/client_connection_spec.rb
169
+ - spec/lib/babylon/component_connection_spec.rb
170
+ - spec/lib/babylon/generator_spec.rb
171
+ - spec/lib/babylon/router/dsl_spec.rb
172
+ - spec/lib/babylon/router_spec.rb
173
+ - spec/lib/babylon/runner_spec.rb
174
+ - spec/lib/babylon/xmpp_connection_spec.rb
175
+ - spec/lib/babylon/xmpp_parser_spec.rb
176
+ - spec/lib/babylon/xpath_helper_spec.rb
177
+ - spec/spec_helper.rb
178
+ - test/babylon_test.rb
179
+ - test/test_helper.rb