Skip to content

Instantly share code, notes, and snippets.

@ore-public
Created February 13, 2014 16:06
Show Gist options
  • Save ore-public/8977928 to your computer and use it in GitHub Desktop.
Save ore-public/8977928 to your computer and use it in GitHub Desktop.
sinatra + ActiveRecord rake task db:xxx の場合のみdatabase.ymlを読みに行くように設定する
require 'active_record'
require 'pg'
require 'erb'
open(File.join(File.dirname(__FILE__), 'config', 'database.yml')) do |f|
ActiveRecord::Base.configurations = YAML.load(ERB.new(f.read).result(binding))
ActiveRecord::Base.establish_connection(ENV['RACK_ENV'])
end
task :before_db do
require './db_initialize'
end
namespace :db do |ns|
ns.tasks.each do |db_task|
db_task.enhance([:before_db])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment