aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-11-25 16:03:33 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-11-25 16:03:33 +0000
commit064877cab83d84fcf7be26e17639c5c2544ffc3d (patch)
treeadb50d1645e0534a8cd40b184aa52c0ba000bb40 /activerecord/lib/active_record/connection_adapters
parenta09824cfcc74847efd0eced904a682713a93d56b (diff)
downloadrails-064877cab83d84fcf7be26e17639c5c2544ffc3d.tar.gz
rails-064877cab83d84fcf7be26e17639c5c2544ffc3d.tar.bz2
rails-064877cab83d84fcf7be26e17639c5c2544ffc3d.zip
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
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb29
1 files changed, 16 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 54fdfd25cd..3d6290f50f 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -75,20 +75,23 @@ module ActiveRecord
# end
#
# Courses.establish_connection( ... )
- def self.establish_connection(spec)
- if spec.instance_of? ConnectionSpecification
- @@defined_connections[self] = spec
- elsif spec.is_a?(Symbol)
- 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
+ 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
+ when Symbol, String
+ establish_connection(configurations[spec.to_s])
+ else
+ 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
- remove_connection
- @@defined_connections[self] = ConnectionSpecification.new(spec, adapter_method)
+ adapter_method = "#{spec[:adapter]}_connection"
+ unless respond_to?(adapter_method) then raise AdapterNotFound end
+ remove_connection
+ establish_connection(ConnectionSpecification.new(spec, adapter_method))
end
end