Hello,
I'm trying to wrap my head around the discovery mechanism for the
ActiveRecord-JDBC drivers. I'm new to Ruby and got stuck on the
initialization of the JdbcAdapter class
ADAPTER_TYPES = ::JdbcSpec.constants.map{ |c|
::JdbcSpec.const_get c }.select{ |c|
c.respond_to? :adapter_selector }.map{|c|
c.adapter_selector }.inject({}) { |h,val|
h[val[0]] = val[1]; h }
def initialize(connection, logger, config)
super(connection, logger)
@config = config
dialect = config[:dialect] || config[:driver]
for reg, func in ADAPTER_TYPES
if reg === dialect.to_s
func.call(@config,self)
end
end
connection.adapter = self
end
This is somehow connected with two methods defined in the module of each
JDBC adapter, e.g:
def self.adapter_selector
[/mysql/i, lambda {|cfg,adapt| adapt.extend(::JdbcSpec::MySQL)}]
End
Could someone please describe what is going on here? How does the
JdbcAdapter know which module use, so that the JdbcAdapter methods are
overridden by those defined in the appropriate adapter module (e.g.
MySQL).
Antoni Mylka
[EMAIL PROTECTED]
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel