class WordPressTools::Database

Attributes

db_name[R]

Public Instance Methods

create(db_name = "wordpress") click to toggle source
# File lib/wordpress_tools/database.rb, line 10
def create(db_name = "wordpress")
  @db_name = db_name

  info("Creating database '#{db_name}'...")
  test_login
  create_database
  success("Database #{db_name} created")
end
create_database() click to toggle source
# File lib/wordpress_tools/database.rb, line 20
def create_database
  run_command(mysql_create_command) ||
    error("Cannot create database '#{db_name}'. Already exists?")
end
db_password() click to toggle source
# File lib/wordpress_tools/database.rb, line 47
def db_password
  options[:db_password]
end
db_user() click to toggle source
# File lib/wordpress_tools/database.rb, line 43
def db_user
  options[:db_user]
end
mysql_command() click to toggle source
# File lib/wordpress_tools/database.rb, line 39
def mysql_command
  "mysql --user='#{db_user}' --password='#{db_password}'"
end
mysql_create_command() click to toggle source
# File lib/wordpress_tools/database.rb, line 30
def mysql_create_command
  [
    mysql_command,
    "--execute='CREATE DATABASE",
    db_name,
    "DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'"
  ].join(' ')
end
test_login() click to toggle source
# File lib/wordpress_tools/database.rb, line 25
def test_login
  run_command("#{mysql_command} --execute='QUIT'") ||
    error("Cannot login to MySQL. Wrong credentials?")
end