Module: ArJdbc

Defined in:
lib/arjdbc/discover.rb,
lib/arjdbc/version.rb,
lib/arjdbc/h2/adapter.rb,
lib/arjdbc/db2/adapter.rb,
lib/arjdbc/jdbc/railtie.rb,
lib/arjdbc/derby/adapter.rb,
lib/arjdbc/jdbc/discover.rb,
lib/arjdbc/mimer/adapter.rb,
lib/arjdbc/mssql/adapter.rb,
lib/arjdbc/mysql/adapter.rb,
lib/arjdbc/hsqldb/adapter.rb,
lib/arjdbc/jdbc/extension.rb,
lib/arjdbc/oracle/adapter.rb,
lib/arjdbc/sybase/adapter.rb,
lib/arjdbc/sqlite3/adapter.rb,
lib/arjdbc/firebird/adapter.rb,
lib/arjdbc/informix/adapter.rb,
lib/arjdbc/mssql/lock_helpers.rb,
lib/arjdbc/postgresql/adapter.rb,
lib/arjdbc/mssql/limit_helpers.rb,
lib/arjdbc/mysql/explain_support.rb,
lib/arjdbc/hsqldb/explain_support.rb,
lib/arjdbc/jdbc/quoted_primary_key.rb,
lib/arjdbc/sqlite3/explain_support.rb,
lib/arjdbc/postgresql/explain_support.rb,
lib/arjdbc/jdbc/missing_functionality_helper.rb,
lib/arjdbc/jdbc/serialized_attributes_helper.rb

Overview

arjdbc/discover.rb: Declare ArJdbc.extension modules in this file that loads a custom module and adapter.

Defined Under Namespace

Modules: DB2, Derby, FireBird, H2, HSQLDB, Informix, Mimer, MissingFunctionalityHelper, MsSQL, MySQL, Oracle, PostgreSQL, QuotedPrimaryKeyExtension, SQLite3, SerializedAttributesHelper, Sybase, Version Classes: Railtie

Class Method Summary collapse

Class Method Details

.discover_extensionsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/arjdbc/jdbc/discover.rb', line 2

def self.discover_extensions
  if defined?(::Gem) && ::Gem.respond_to?(:find_files)
    files = ::Gem.find_files('arjdbc/discover')
  else
    files = $LOAD_PATH.map do |p|
      discover = File.join(p, 'arjdbc', 'discover.rb')
      File.exist?(discover) ? discover : nil
    end.compact
  end
  files.each do |f|
    puts "Loading #{f}" if $DEBUG
    require f
  end
end

.extension(name, &block) ⇒ Object

Defines an AR-JDBC extension. An extension consists of a declaration using this method and an ArJdbc::XYZ module that contains implementation and overrides for methods in ActiveRecord::ConnectionAdapters::AbstractAdapter. When you declare your extension, you provide a block that detects when a database configured to use the extension is present and loads the necessary code for it. AR-JDBC will patch the code into the base ActiveRecord::ConnectionAdapters::JdbcAdapter by extending an instance of it with your extension module.

name should be a symbol that is the name of a module to be defined under the ArJdbc module.

block should be a one- or two-arity block that receives the dialect name or driver class name as the first argument, and optionally the whole database configuration hash as a second argument.

Example:

ArJdbc.extension :Frob do |name|
  if name =~ /frob/i
    # arjdbc/frob.rb should contain the implementation
    require 'arjdbc/frob'
    true
  end
end


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/arjdbc/jdbc/extension.rb', line 29

def self.extension(name,&block)
  if const_defined?(name)
    mod = const_get(name)
  else
    mod = const_set(name, Module.new)
  end
  (class << mod; self; end).instance_eval do
    unless respond_to?(:adapter_matcher)
      define_method :adapter_matcher do |_name, config|
        if block.arity == 1
          block.call(_name) ? mod : false
        else
          block.call(_name, config) ? mod : false
        end
      end
    end
  end
end