Created
February 13, 2014 16:06
-
-
Save ore-public/8977928 to your computer and use it in GitHub Desktop.
sinatra + ActiveRecord rake task db:xxx の場合のみdatabase.ymlを読みに行くように設定する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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