Permalink
Browse files

Started the work to create configs for multiple apps at once. WIP.

  • Loading branch information...
1 parent 0729d2e commit b52f45e5b3c72160067e942cf0be7c7d5ca96de6 @alloy alloy committed Jun 13, 2008
Showing with 27 additions and 4 deletions.
  1. +11 −2 PassengerApplication.rb
  2. +1 −0 shared_passenger_behaviour.rb
  3. +15 −2 test/passenger_application_test.rb
@@ -1,6 +1,7 @@
require 'osx/cocoa'
include OSX
+require 'yaml'
require File.expand_path('../shared_passenger_behaviour', __FILE__)
class PassengerApplication < NSObject
@@ -9,6 +10,10 @@ class PassengerApplication < NSObject
CONFIG_UNINSTALLER = File.expand_path('../config_uninstaller.rb', __FILE__)
CONFIG_INSTALLER = File.expand_path('../config_installer.rb', __FILE__)
+ def self.startApplications(apps)
+ SharedPassengerBehaviour.execute "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{apps.map { |app| app.to_hash }.to_yaml}'"
+ end
+
kvc_accessor :host, :path
def init
@@ -50,12 +55,12 @@ def restart(sender = nil)
def remove
p "Removing application: #{path}"
- execute "/usr/bin/env ruby '#{CONFIG_UNINSTALLER}' '#{config_path}' '/etc/hosts' '#{@host}'"
+ execute "/usr/bin/env ruby '#{CONFIG_UNINSTALLER}' '/etc/hosts' '#{config_path}' '#{@host}'"
end
def save_config!(extra_command = nil)
p "Saving configuration: #{config_path}"
- command = "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '#{config_path}' '/etc/hosts' '#{@host}' '#{@path}'"
+ command = "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '/etc/hosts' '#{config_path}' '#{@host}' '#{@path}'"
command << " '#{extra_command}'" if extra_command
execute command
end
@@ -69,4 +74,8 @@ def rbSetValue_forKey(value, key)
@dirty = true
(@new_app ? start : restart) unless @host.empty? or @path.empty?
end
+
+ def to_hash
+ {'config_path' => config_path, 'host' => @host, 'path' => @path}
+ end
end
@@ -7,6 +7,7 @@ module SharedPassengerBehaviour
def execute(command)
apple_script "do shell script \"#{command}\" with administrator privileges"
end
+ module_function :execute
def apple_script(command)
script = NSAppleScript.alloc.initWithSource(command)
@@ -72,7 +72,7 @@ def after_setup
end
it "should be able to save the config file" do
- passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '#{passenger_app.config_path}' '/etc/hosts' 'het-manfreds-blog.local' '/Users/het-manfred/rails code/blog'")
+ passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{passenger_app.config_path}' 'het-manfreds-blog.local' '/Users/het-manfred/rails code/blog'")
passenger_app.save_config!
end
@@ -114,7 +114,20 @@ def after_setup
end
it "should remove an application" do
- passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_UNINSTALLER}' '#{passenger_app.config_path}' '/etc/hosts' 'het-manfreds-blog.local'")
+ passenger_app.expects(:execute).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_UNINSTALLER}' '/etc/hosts' '#{passenger_app.config_path}' 'het-manfreds-blog.local'")
passenger_app.remove
end
+
+ it "should return it's attributes as a hash" do
+ passenger_app.to_hash.should == {'config_path' => passenger_app.config_path, 'host' => passenger_app.host, 'path' => passenger_app.path}
+ end
+
+ it "should start multiple applications at once" do
+ app1 = PassengerApplication.alloc.initWithPath('/rails/app1')
+ app2 = PassengerApplication.alloc.initWithPath('/rails/app2')
+
+ SharedPassengerBehaviour.expects(:execute).times(1).with("/usr/bin/env ruby '#{PassengerApplication::CONFIG_INSTALLER}' '/etc/hosts' '#{[app1.to_hash, app2.to_hash].to_yaml}'")
+
+ PassengerApplication.startApplications [app1, app2]
+ end
end

0 comments on commit b52f45e

Please sign in to comment.