Skip to content

Commit a2faad8

Browse files
committed
one discover.rb file is enough - move jdbc/discover.rb into jdbc/extension.rb
1 parent f43c2a5 commit a2faad8

File tree

3 files changed

+36
-42
lines changed

3 files changed

+36
-42
lines changed

lib/arjdbc/jdbc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
require 'arjdbc/jdbc/adapter'
2-
require 'arjdbc/jdbc/discover'
2+
module ArJdbc; self.discover_extensions; end

lib/arjdbc/jdbc/discover.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/arjdbc/jdbc/extension.rb

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
module ArJdbc
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.
2+
3+
# Defines an AR-JDBC extension. An extension consists of a declaration using
4+
# this method and an ArJdbc::XYZ module that contains implementation and
5+
# overrides for methods in ActiveRecord::ConnectionAdapters::AbstractAdapter.
6+
# When you declare your extension, you provide a block that detects when a
7+
# database configured to use the extension is present and loads the necessary
8+
# code for it. AR-JDBC will patch the code into the base JdbcAdapter by
9+
# extending an instance of it with your extension module.
1110
#
12-
# +name+ should be a symbol that is the name of a module to be
13-
# defined under the +ArJdbc+ module.
11+
# +name+ the name of a module to be defined under the +ArJdbc+ module.
1412
#
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
18-
# argument.
13+
# +block+ should be a one- or two-arity block that receives the dialect name
14+
# or driver class name as the first argument, and optionally the whole
15+
# database configuration hash as a second argument
1916
#
2017
# Example:
2118
#
22-
# ArJdbc.extension :Frob do |name|
23-
# if name =~ /frob/i
24-
# # arjdbc/frob.rb should contain the implementation
25-
# require 'arjdbc/frob'
26-
# true
27-
# end
19+
# ArJdbc.extension :FRoB do |name|
20+
# if name =~ /frob/i
21+
# require 'arjdbc/frob' # contains ArJdbc::FRoB
22+
# true
2823
# end
24+
# end
25+
#
2926
def self.extension(name, &block)
3027
if const_defined?(name)
3128
mod = const_get(name)
@@ -44,4 +41,21 @@ def self.extension(name, &block)
4441
end
4542
end
4643
end
44+
45+
private
46+
def self.discover_extensions
47+
if defined?(::Gem) && ::Gem.respond_to?(:find_files)
48+
files = ::Gem.find_files('arjdbc/discover')
49+
else
50+
files = $LOAD_PATH.map do |p|
51+
discover = File.join(p, 'arjdbc', 'discover.rb')
52+
File.exist?(discover) ? discover : nil
53+
end.compact
54+
end
55+
files.each do |file|
56+
puts "Loading AR-JDBC extension #{file}" if $DEBUG
57+
require file
58+
end
59+
end
60+
4761
end

0 commit comments

Comments
 (0)