julien51-babylon 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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, xml_stanza = nil)
34
- Babylon.logger.info {
35
- "ROUTING TO #{controller_name}::#{action_name}"
36
- }
37
- stanza = nil
38
- stanza = Kernel.const_get(action_name.capitalize).new(xml_stanza) if xml_stanza
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
- it "should instantiate the route's stanza" do
105
- Kernel.should_receive(:const_get).with(@action.capitalize).and_return(Babylon::Base::Stanza)
106
- Babylon::Base::Stanza.should_receive(:new).with(@xml).and_return(@mock_stanza)
107
- @router.execute_route(@controller, @action, @xml)
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
- it "should instantiate the route's controller" do
111
- @controller.should_receive(:new).and_return(@mock_controller)
112
- @router.execute_route(@controller, @action, @xml)
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
- OPTIONS = {
8
- :command => "run",
9
- :environment => "development",
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: #{OPTIONS[:command]}") { |OPTIONS[:command]| }
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: #{OPTIONS[:environment]}") { |OPTIONS[:environment]| }
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: #{OPTIONS[:name]}") { |OPTIONS[:name]| }
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 => [OPTIONS[:command], '--', OPTIONS[:environment]],
42
- :app_name => OPTIONS[: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.3
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-23 00:00:00 -07:00
12
+ date: 2009-05-31 00:00:00 -07:00
13
13
  default_executable: babylon
14
14
  dependencies: []
15
15