Class: DBGet::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/dbget/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Controller

Returns a new instance of Controller.



7
8
9
10
# File 'lib/dbget/controller.rb', line 7

def initialize(options)
  @dump = DBGet::Dump.new(options)
  @config = DBGet::Config.instance
end

Class Method Details

.boot(options) ⇒ Object



3
4
5
# File 'lib/dbget/controller.rb', line 3

def self.boot(options)
  self.new(options).run!
end

Instance Method Details

#finalize_dumpObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dbget/controller.rb', line 27

def finalize_dump
  if @dump.in_cache? @dump.cache_file
    message = "Found cached file, no need to decrypt."
  else
    message = "Decrypting #{@dump.encrypted_dump}..."
  end

  Utils.say_with_time message do
    @dump.decrypted_dump = @dump.decrypt_dump
  end

  @dump.set_final_db
end

#load_dumpObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dbget/controller.rb', line 41

def load_dump
  Utils.say_with_time "Dumping, this may take a while" do
    case @dump.db_type
    when 'mysql'
      DBGet::Loaders::MySql.boot(@dump, @config).load!
    when 'mongo'
      DBGet::Loaders::Mongo.boot(@dump, @config).load!
    else
      raise "Dump is not supported!"
    end
  end

end

#run!Object



12
13
14
15
16
17
18
# File 'lib/dbget/controller.rb', line 12

def run!
  user_allowed?
  @dump.prepare
  finalize_dump
  load_dump
  status_report
end

#status_reportObject



55
56
57
58
59
# File 'lib/dbget/controller.rb', line 55

def status_report
  Utils.say "Dump for #{@dump.db} done!"
  Utils.say "Source: #{@dump.decrypted_dump}"
  Utils.say "Target: #{@dump.target_db}"
end

#user_allowed?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/dbget/controller.rb', line 20

def user_allowed?
  unless @config['users'].include?(@dump.user)
    raise "User not allowed to dump"
    exit 1
  end
end