2 # Defines an AR-JDBC extension. An extension consists of a
3 # declaration using this method and an ArJdbc::XYZ module that
4 # contains implementation and overrides for methods in
5 # ActiveRecord::ConnectionAdapters::AbstractAdapter. When you
6 # declare your extension, you provide a block that detects when a
7 # database configured to use the extension is present and loads the
8 # necessary code for it. AR-JDBC will patch the code into the base
9 # ActiveRecord::ConnectionAdapters::JdbcAdapter by extending an
10 # instance of it with your extension module.
12 # +name+ should be a symbol that is the name of a module to be
13 # defined under the +ArJdbc+ module.
15 # +block+ should be a one- or two-arity block that receives the
16 # dialect name or driver class name as the first argument, and
17 # optionally the whole database configuration hash as a second
22 # ArJdbc.extension :Frob do |name|
24 # # arjdbc/frob.rb should contain the implementation
25 # require 'arjdbc/frob'
29 def self.extension(name,&block)
30 if const_defined?(name)
33 mod = const_set(name, Module.new)
35 (class << mod; self; end).instance_eval do
36 unless respond_to?(:adapter_matcher)
37 define_method :adapter_matcher do |name, config|
39 block.call(name) ? mod : false
41 block.call(name, config) ? mod : false