Sha256: 1f598f46af8f7166ce9e54774f666bc31c007f9edeed6aa37fa4990351475cb7

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Siringa
  class SiringaController < ApplicationController

    def load_definition
      result = Siringa.load_definition(params['definition'].to_sym, options)
      render json: result, status: :created
    rescue ArgumentError => exception
      render json: { error: exception.to_s }, status: :method_not_allowed
    rescue StandardError => exception
      render json: { error: exception.to_s }, status: :internal_server_error
    end

    def dump
      Siringa.keep_five_dumps(Siringa.ordered_dumps)
      result = Siringa.dump_to(Siringa.dump_file_name)
      if result[:status]
        resp = { :text => "DB dumped at #{result[:dump_path]}",
                 :status => :created }
      else
        resp = { :text => "DB dump FAILED!\nError:\n#{result[:error]}",
                 :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[:status]
          resp = { :text => "DB restored from #{result[:dump_path]}",
                   :status => :accepted }
        else
          resp = { :text => "DB restore FAILED!\nError:\n#{result[:error]}",
                   :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

    private

    # Returns the arguments to be passed to the definition
    #
    # @return [Hash] arguments of the definition
    def options
      params[:siringa_args]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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