julien51-babylon 0.1.3 → 0.1.4
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/lib/babylon/router.rb +11 -6
- data/spec/lib/babylon/router_spec.rb +18 -8
- data/templates/babylon/script/component +9 -10
- metadata +2 -2
data/lib/babylon/router.rb
CHANGED
@@ -30,12 +30,17 @@ module Babylon
|
|
30
30
|
##
|
31
31
|
# Executes the route for the given xml_stanza, by instantiating the controller_name, calling action_name and sending
|
32
32
|
# the result to the connection
|
33
|
-
def execute_route(controller_name, action_name,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
def execute_route(controller_name, action_name, stanza = nil)
|
34
|
+
begin
|
35
|
+
stanza = Kernel.const_get(action_name.capitalize).new(stanza) if stanza
|
36
|
+
Babylon.logger.info {
|
37
|
+
"ROUTING TO #{controller_name}::#{action_name} with #{stanza.class}"
|
38
|
+
}
|
39
|
+
rescue NameError
|
40
|
+
Babylon.logger.info {
|
41
|
+
"ROUTING TO #{controller_name}::#{action_name} with #{stanza.class}"
|
42
|
+
}
|
43
|
+
end
|
39
44
|
controller = controller_name.new(stanza)
|
40
45
|
controller.perform(action_name)
|
41
46
|
connection.send_xml(controller.evaluate)
|
@@ -101,15 +101,25 @@ describe Babylon::StanzaRouter do
|
|
101
101
|
@mock_controller.stub!(:perform).with(@action)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
describe "when the Stanza class exists" do
|
105
|
+
it "should instantiate the route's stanza " do
|
106
|
+
Kernel.should_receive(:const_get).with(@action.capitalize).and_return(Babylon::Base::Stanza)
|
107
|
+
Babylon::Base::Stanza.should_receive(:new).with(@xml).and_return(@mock_stanza)
|
108
|
+
@router.execute_route(@controller, @action, @xml)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should instantiate the route's controller" do
|
112
|
+
@controller.should_receive(:new).with(@mock_stanza).and_return(@mock_controller)
|
113
|
+
@router.execute_route(@controller, @action, @xml)
|
114
|
+
end
|
108
115
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
|
117
|
+
describe "when the stanza class doesn't exist" do
|
118
|
+
it "should instantiate the route's controller with the xml" do
|
119
|
+
Kernel.should_receive(:const_get).with(@action.capitalize).and_raise(NameError)
|
120
|
+
@controller.should_receive(:new).with(@xml).and_return(@mock_controller)
|
121
|
+
@router.execute_route(@controller, @action, @xml)
|
122
|
+
end
|
113
123
|
end
|
114
124
|
|
115
125
|
it "should call perform on the controller with the action's name" do
|
@@ -4,11 +4,9 @@ require 'daemons'
|
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
# default options
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:name => "#{Dir.pwd.split("/").last}",
|
11
|
-
}
|
7
|
+
command = "run"
|
8
|
+
environment = "development"
|
9
|
+
name = "#{Dir.pwd.split("/").last}"
|
12
10
|
|
13
11
|
ARGV.options do |o|
|
14
12
|
script_name = File.basename($0)
|
@@ -21,13 +19,13 @@ ARGV.options do |o|
|
|
21
19
|
|
22
20
|
o.on("-c", "--command=[run|start|stop|restart]", String,
|
23
21
|
"The command you'd like to execute",
|
24
|
-
"Default: #{
|
22
|
+
"Default: #{command}") { |command| }
|
25
23
|
o.on("-e", "--environment=env", String,
|
26
24
|
"The environment to run the application (you should have defined the argument into config/config.yaml)",
|
27
|
-
"Default: #{
|
25
|
+
"Default: #{environment}") { |environment| }
|
28
26
|
o.on("-n", "--name=app_name", String,
|
29
27
|
"Name of your application. The pid_file will be name after this.",
|
30
|
-
"Default: #{
|
28
|
+
"Default: #{name}") { |name| }
|
31
29
|
|
32
30
|
o.separator ""
|
33
31
|
|
@@ -38,10 +36,11 @@ end
|
|
38
36
|
|
39
37
|
|
40
38
|
options = {
|
41
|
-
:ARGV => [
|
42
|
-
:app_name =>
|
39
|
+
:ARGV => [command, '--', environment],
|
40
|
+
:app_name => name,
|
43
41
|
:dir => "../tmp/pids/",
|
44
42
|
:multiple => false,
|
45
43
|
:backtrace => true
|
46
44
|
}
|
45
|
+
$app_name = options[:app_name]
|
47
46
|
Daemons.run(File.dirname(__FILE__) + '/../config/boot.rb', options)
|
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.1.
|
4
|
+
version: 0.1.4
|
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-05-
|
12
|
+
date: 2009-05-31 00:00:00 -07:00
|
13
13
|
default_executable: babylon
|
14
14
|
dependencies: []
|
15
15
|
|