class Rbfam::DbConfig

Public Instance Methods

bootstrap!() click to toggle source
# File lib/rbfam/db_config.rb, line 13
def bootstrap!
  ensure_action("Are you sure you'd like to completely rebuild the database? This takes around 10 minutes.") do
    Rake::Task["db:reset"].invoke
  end
end
clear!() click to toggle source
# File lib/rbfam/db_config.rb, line 25
def clear!
  ensure_action("Are you sure you'd like drop the database? This can't be un-done.") do
    Rake::Task["db:drop"].invoke
  end
end
connect() click to toggle source
# File lib/rbfam/db_config.rb, line 31
def connect
  ActiveRecord::Base.establish_connection(scoped_config)
end
scoped_config() click to toggle source
# File lib/rbfam/db_config.rb, line 9
def scoped_config
  config[env]
end
seed!() click to toggle source
# File lib/rbfam/db_config.rb, line 19
def seed!
  ensure_action("Are you sure you'd like to re-seed the database? This is faster than bootstrap!, and won't delete data.") do
    Rake::Task["db:seed"].invoke
  end
end

Private Instance Methods

ensure_action(string) { |block| ... } click to toggle source
# File lib/rbfam/db_config.rb, line 37
def ensure_action(string, &block)
  puts "#{string} (y/n)"
  response = gets.chomp.downcase
  if response == ?y
    load_rakefile
    yield block
    true
  else 
    puts "Bailing, no changes were made."
    false
  end
end
load_rakefile() click to toggle source
# File lib/rbfam/db_config.rb, line 50
def load_rakefile
  Rake.load_rakefile(File.join(File.dirname(__FILE__), "..", "..", "Rakefile"))
end