I''m digging into rails source code.
But I''ve got a problem in undestading actionrecord::base source code
which is connection_specification.rb.
In the body of establish_connection method,
def self.establish_connection(spec = nil)
case spec
when nil
raise AdapterNotSpecified unless defined? RAILS_ENV
establish_connection(RAILS_ENV)
when ConnectionSpecification
clear_active_connection_name
@active_connection_name = name
@@defined_connections[name] = spec
when Symbol, String
if configuration = configurations[spec.to_s]
establish_connection(configuration)
else
raise AdapterNotSpecified, "#{spec} database is not
configured"
end
else
spec = spec.symbolize_keys
unless spec.key?(:adapter) then raise AdapterNotSpecified,
"database configuration does not specify adapter" end
adapter_method = "#{spec[:adapter]}_connection"
unless respond_to?(adapter_method) then raise AdapterNotFound,
"database configuration specifies nonexistent #{spec[:adapter]}
adapter"
end
remove_connection
establish_connection(ConnectionSpecification.new(spec,
adapter_method))
end
end
there is case statement.
when spec is ConnectionSpecification, @active_connection_name is set by
name.
But I couldn''t find what the hack is ''name''
variable..
Do you have any idea or where is that variable set?
Thanks in advance..
--
Posted via http://www.ruby-forum.com/.
On Aug 13, 2006, at 11:50 AM, eskim wrote:> I''m digging into rails source code. > But I''ve got a problem in undestading actionrecord::base source code > which is connection_specification.rb. > > In the body of establish_connection method, > > def self.establish_connection(spec = nil) > case spec > when nil > raise AdapterNotSpecified unless defined? RAILS_ENV > establish_connection(RAILS_ENV) > when ConnectionSpecification > clear_active_connection_name > @active_connection_name = name > @@defined_connections[name] = spec > when Symbol, String > if configuration = configurations[spec.to_s] > establish_connection(configuration) > else > raise AdapterNotSpecified, "#{spec} database is not > configured" > end > else > spec = spec.symbolize_keys > unless spec.key?(:adapter) then raise AdapterNotSpecified, > "database configuration does not specify adapter" end > adapter_method = "#{spec[:adapter]}_connection" > unless respond_to?(adapter_method) then raise > AdapterNotFound, > "database configuration specifies nonexistent #{spec[:adapter]} > adapter" > end > remove_connection > establish_connection(ConnectionSpecification.new(spec, > adapter_method)) > end > end > > there is case statement. > when spec is ConnectionSpecification, @active_connection_name is > set by > name. > > But I couldn''t find what the hack is ''name'' variable.. > > Do you have any idea or where is that variable set? > > Thanks in advance..self.name. Name of the class. -- Chris Wanstrath http://errtheblog.com
Maybe Matching Threads
- [PATCH] Support for DB Clusters/Replication in ActiveRecord (RFC)
- database adaptor password in production.log
- Rails not properly handling Oracle db connections/sesions in dev mode
- Helps!!!!! Rails database connection guru needed!!!!!!!
- Database connection parameters are tied to the filesystem