Class: Dbmanager::Adapters::Mysql::Loader

Inherits:
Object
  • Object
show all
Includes:
Connectable
Defined in:
lib/dbmanager/adapters/mysql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connectable

#params

Constructor Details

#initialize(target, tmp_file) ⇒ Loader

Returns a new instance of Loader.



60
61
62
63
# File 'lib/dbmanager/adapters/mysql.rb', line 60

def initialize(target, tmp_file)
  @target   = target
  @tmp_file = tmp_file
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



58
59
60
# File 'lib/dbmanager/adapters/mysql.rb', line 58

def target
  @target
end

#tmp_fileObject (readonly)

Returns the value of attribute tmp_file.



58
59
60
# File 'lib/dbmanager/adapters/mysql.rb', line 58

def tmp_file
  @tmp_file
end

Instance Method Details

#create_db_if_missingObject



70
71
72
# File 'lib/dbmanager/adapters/mysql.rb', line 70

def create_db_if_missing
  Dbmanager.execute! create_db_if_missing_command
end

#create_db_if_missing_commandObject



82
83
84
# File 'lib/dbmanager/adapters/mysql.rb', line 82

def create_db_if_missing_command
  "bundle exec rake db:create RAILS_ENV=#{target.name}"
end

#loadObject



74
75
76
# File 'lib/dbmanager/adapters/mysql.rb', line 74

def load
  Dbmanager.execute! load_command
end

#load_commandObject



78
79
80
# File 'lib/dbmanager/adapters/mysql.rb', line 78

def load_command
  "mysql #{params(target)} < '#{tmp_file}'"
end

#runObject



65
66
67
68
# File 'lib/dbmanager/adapters/mysql.rb', line 65

def run
  create_db_if_missing
  load
end