Class: Siringa::SiringaController

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

Instance Method Summary collapse

Instance Method Details

#dump ⇒ Object



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

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 ⇒ Object



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

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

#restore ⇒ Object



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

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