require 'yaml' require 'erb' require 'sequel' # faking out the branch-name detection in Protopipe's database.yml. we may want to integrate with Rails later. raise "Rails integration is not complete" if defined?(Rails) module Rails def self.root; @@root end def self.root=(x); @@root=x end def self.env; "development" end #hardcoding development environment YML_PATH = "config/database.yml" # hard-coding the location of the yml file end module Hydroponics def self.db; @@db; end def self.db=(x); @@db = x; end module Setup def convert_rails_yml_to_sequel_config(yml) { :adapter => yml[Rails.env]['adapter'], :host => yml[Rails.env]['host'], :database => yml[Rails.env]['database'], :user => yml[Rails.env]['username'], :password => yml[Rails.env]['password'] } end def get_db_from_local_rails_project(proj_root) yml_path = File.join(proj_root, Rails::YML_PATH) raise "Aborting: no database.yml file found" unless File.exists?(yml_path) Rails.root = proj_root # protopipe has its YML file as an ERB which references Rails.root yml = YAML::load(ERB.new(File.open(yml_path).read).result(binding)) dbconfig = convert_rails_yml_to_sequel_config(yml) Hydroponics.db = Sequel.connect(dbconfig) dbconfig.merge(:password => "---") # output end def raise_max_packet_size Hydroponics.db.execute("set global max_allowed_packet=1048576000;") end end end