Sha256: 953747870e4a36b65d4ecfba8c08a12d449debb0082280076d9bcd82ff459274

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Siringa
  class SiringaController < ApplicationController

    def load
      Siringa.load_definition(params['definition'].to_sym)
      resp = { :text => "Definition #{params['definition']} loaded.", :status => :created }
    rescue ArgumentError => exception
      resp = { :text => exception.to_s, :status => :method_not_allowed }
    rescue => exception
      resp = { :text => exception.to_s, :status => :internal_server_error }
    ensure
      render resp
    end

    def dump
      result = Siringa.dump_to(Siringa.dump_file_name)
      if result[:success]
        Siringa.keep_five_dumps(Siringa.ordered_dumps)
        resp = { :text => "DB dumped at #{result[:file_name]}",
                 :status => :created }
      else
        resp = { :text => "DB dump FAILED!\nError:\n#{result[:output]}",
                 :status => :internal_server_error }
      end

      render resp
    end

    def restore
      last_dump = Siringa.ordered_dumps.last
      if last_dump
        result = Siringa.restore_from(last_dump)
        if result[:success]
          resp = { :text => "DB restored from #{result[:file_name]}",
                   :status => :accepted }
        else
          resp = { :text => "DB restore FAILED!\nError:\n#{result[:output]}",
                   :status => :internal_server_error }
        end
      else
        resp = { :text => "DB restore FAILED!\nThere is no dump to restore from.",
                 :status => :method_not_allowed }
      end

      render resp
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
siringa-0.0.1 app/controllers/siringa/siringa_controller.rb