Class: Ferry::Filler

Inherits:
Utilities show all
Defined in:
lib/ferry/filler.rb

Instance Method Summary collapse

Methods inherited from Utilities

#check_valid_db, #check_valid_filetype, #db_connect, #execute, #print_version

Instance Method Details

#fill(environment, content) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ferry/filler.rb', line 6

def fill(environment, content)
  # check to make sure db exists
  # drop database
  # prompt user to confirm that they will erase the current env db and refill
  # fill
  @dbadapter = db_connect(environment)
  @dbenv = environment
  @dbname = YAML::load(IO.read("config/database.yml"))[@dbenv]["database"]
  @filepath = content
  @commands = { "sqlite3" => "cat #{@filepath} | sqlite3 #{@dbname}.db",
                "postgresql" => "psql -d #{@dbname} -f #{@filepath}",
                "mysql2" => "mysql -p #{@dbname} < #{@filepath}"
              }
  if check_valid_db(@dbadapter) && check_valid_filetype(@filepath)
    execute(@commands[@dbadapter])
  else
    raise "Dump failed: Check to make sure #{@filepath} exists and is the proper type and that #{@dbenv} is supported in our documentation."
    return false
  end
end