Establish_connection method

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…

On Aug 13, 2006, at 11:50 AM, eskim wrote:

      establish_connection(RAILS_ENV)
      end
      remove_connection

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 W.
http://errtheblog.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs