1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added option to establish_connection where you'll be able to leave out the parameter to have it use the RAILS_ENV environment variable

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2004-11-25 16:03:33 +00:00
parent a09824cfcc
commit 064877cab8
2 changed files with 18 additions and 13 deletions

View file

@ -1,5 +1,7 @@
*CVS*
* Added option to establish_connection where you'll be able to leave out the parameter to have it use the RAILS_ENV environment variable
* Added ADO-based SQLServerAdapter (only works on Windows) [Joey Gibson]
* Fixed problems with primary keys and postgresql sequences (#230) [Tim Bates]

View file

@ -75,20 +75,23 @@ module ActiveRecord
# end
#
# Courses.establish_connection( ... )
def self.establish_connection(spec)
if spec.instance_of? ConnectionSpecification
def self.establish_connection(spec = nil)
case spec
when nil
raise AdapterNotSpecified unless defined? RAILS_ENV
establish_connection(RAILS_ENV)
when ConnectionSpecification
@@defined_connections[self] = spec
elsif spec.is_a?(Symbol)
when Symbol, String
establish_connection(configurations[spec.to_s])
else
if spec.nil? then raise AdapterNotSpecified end
symbolize_strings_in_hash(spec)
unless spec.key?(:adapter) then raise AdapterNotSpecified end
adapter_method = "#{spec[:adapter]}_connection"
unless methods.include?(adapter_method) then raise AdapterNotFound end
unless respond_to?(adapter_method) then raise AdapterNotFound end
remove_connection
@@defined_connections[self] = ConnectionSpecification.new(spec, adapter_method)
establish_connection(ConnectionSpecification.new(spec, adapter_method))
end
end