Top Level Namespace

Defined Under Namespace

Modules: Caploy, Database, Util

Instance Method Summary collapse

Instance Method Details

#config_file_path(config_file_name) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/caploy/recipes/setup.rb', line 46

def config_file_path(config_file_name)
  config_file = "#{rails_root}/config/#{config_file_name}"
  if File.exists? config_file
    config_file
  else
    puts "\e[0;31mNo config file '#{config_file}'"
    nil
  end
end

#create_databaseObject



66
67
68
69
70
71
72
# File 'lib/caploy/recipes/setup.rb', line 66

def create_database
  create_sql = "      CREATE DATABASE \#{db_name};\n  SQL\n\n  run \"mysql --user=\#{db_admin_user} --password=\#{db_admin_password} --execute=\\\"\#{create_sql}\\\"\"\nend\n"

#database_exits?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
# File 'lib/caploy/recipes/setup.rb', line 56

def database_exits?
  exists = false

  run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"show databases;\"" do |channel, stream, data|
    exists = exists || data.include?(db_name)
  end

  exists
end

#render_erb_template(template_path, vars = {}) ⇒ Object



3
4
5
6
7
8
# File 'lib/caploy/render.rb', line 3

def render_erb_template(template_path, vars={})
  raise "file '#{template_path}' not exists" unless File.exist? template_path

  template = File.open(template_path, 'r').read
  Erubis::Eruby.new(template).result(vars)
end

#setup_database_permissionsObject



74
75
76
77
78
79
80
# File 'lib/caploy/recipes/setup.rb', line 74

def setup_database_permissions
  grant_sql = "     GRANT ALL PRIVILEGES ON \#{db_name}.* TO \#{db_user_name}@localhost IDENTIFIED BY '\#{db_user_password}';\n  SQL\n\n  run \"mysql --user=\#{db_admin_user} --password=\#{db_admin_password} --execute=\\\"\#{grant_sql}\\\"\"\nend\n"