controller/applications.rb in ruby-station-0.0.4 vs controller/applications.rb in ruby-station-0.1.0

- old
+ new

@@ -1,35 +1,48 @@ +require 'json' + class Applications < Controller map '/applications' + provide :json, :type => "application/json" do |action, value| + value.to_json + end layout{|path, ext| - "default" unless path =~ /\Ado_/ + "default" unless path =~ /\A_/ } def install - if request["name"] + session[:source_type] = request["by"] + + case session[:source_type] + when "name" @name = request["name"] session[:gemname] = @name - else + session[:messages] = [] + when "file" tempfile = request["gem"][:tempfile] @filename = request["gem"][:filename] @size = tempfile.size session[:tempfile] = tempfile + else + raise "unknown install source type: #{session[:source_type]}" end end - def do_install - if gemname = session[:gemname] + def _install + case session[:source_type] + when "name" + gemname = session[:gemname] result, name, version = GemManager.install_gem(gemname) - elsif session[:tempfile] + when "file" path = session[:tempfile].path result, name, version = GemManager.install_file(path) else - raise + raise "unknown install source type: #{session[:source_type]}" end - unless Application.first(:name => name, :version => version) + if result and not Application.first(:name => name, :version => version) Application.create({ :pid => nil, :port => 30000 + rand(9999), :name => name, :version => version, @@ -38,30 +51,27 @@ session.clear h result end - def create - end - - def show(name) - end - def uninstall(id) - app = Application.get(id) - raise "application not found(id=#{id})" unless app - - @app = app + if app = Application.get(id) + @app = app + else + flash[:error] = "The application (id=#{id}) is already uninstalled." + redirect MainController.r(:notfound) + end end - def do_uninstall(id) - app = Application.get(id) - raise "application not found(id=#{id})" unless app - - result = GemManager.uninstall(app.name, app.version) - app.destroy - result + def _uninstall(id) + if app = Application.get(id) + result = GemManager.uninstall(app.name, app.version) + app.destroy + result + else + "" + end end def start(id) app = Application.get(id) raise "application not found(id=#{id})" unless app @@ -78,7 +88,6 @@ app.stop redirect_referer end - end