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.



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

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

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

#tmp_fileObject (readonly)

Returns the value of attribute tmp_file.



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

def tmp_file
  @tmp_file
end

Instance Method Details

#create_db_if_missingObject



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

def create_db_if_missing
  Dbmanager.execute! create_db_if_missing_command
end

#create_db_if_missing_commandObject



95
96
97
# File 'lib/dbmanager/adapters/mysql.rb', line 95

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

#loadObject



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

def load
  Dbmanager.execute! load_command
end

#load_commandObject



87
88
89
# File 'lib/dbmanager/adapters/mysql.rb', line 87

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

#load_command_sshObject



91
92
93
# File 'lib/dbmanager/adapters/mysql.rb', line 91

def load_command_ssh
  "mysql #{params target}"
end

#runObject



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

def run
  create_db_if_missing
  load
end