model/application.rb in ruby-station-0.1.3 vs model/application.rb in ruby-station-0.1.4.rc1

- old
+ new

@@ -5,10 +5,42 @@ property :pid, Integer property :port, Integer property :name, String property :version, String + # Install the speficied gem and create an Application + def self.install(by, value) + case by + when :name + result, name, version = GemManager.install_gem(value) + when :file + result, name, version = GemManager.install_file(value) + else + raise "invalid parameter: by => #{by}" + end + + unless Application.first(:name => name, :version => version) + Application.create({ + :pid => nil, + :port => 30000 + rand(9999), + :name => name, + :version => version, + }) + end + + return result + end + + # Uninstall the gem and destroy myself + def uninstall + result = GemManager.uninstall(self.name, self.version) + self.destroy + + return result + end + + # Start the app in background def start return if self.pid cmd = [ gem_env(), @@ -24,17 +56,19 @@ stopped } self.save end + # Kill the app if running def stop if self.pid Servant.kill(self.pid) stopped end end + # Returns a string contains name and version def full_name "#{self.name}-#{self.version}" end private @@ -57,6 +91,6 @@ "GEM_HOME='#{Conf.gem_dir}'" end end DataMapper.auto_upgrade! -Application.all.each{|a| a.update_attributes(:pid => nil)} +Application.all.each{|a| a.update(:pid => nil)}