Class: Siringa::SiringaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/siringa/siringa_controller.rb

Instance Method Summary collapse

Instance Method Details

#dump ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/siringa/siringa_controller.rb', line 13

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

#load_definition ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/controllers/siringa/siringa_controller.rb', line 4

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

#restore ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/siringa/siringa_controller.rb', line 27

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