Permalink
Browse files

Add automatic transform for jruby_adapter => adapter when running und…

…er JRuby. Closes #14.
  • Loading branch information...
1 parent c591568 commit 4f86010cdd1860fdd2e090603ccfd05517640b91 @rsutphin rsutphin committed Sep 1, 2011
Showing with 46 additions and 2 deletions.
  1. +4 −1 CHANGELOG.markdown
  2. +7 −0 README.markdown
  3. +12 −1 lib/bcdatabase.rb
  4. +23 −0 spec/bcdatabase_spec.rb
View
@@ -1,9 +1,12 @@
Bcdatabase history
==================
-1.1.1
+1.2.0
-----
+- Add automatic transform for `jruby_adapter` when running under
+ JRuby. (#14)
+
1.1.0
-----
View
@@ -221,6 +221,13 @@ JRuby (tested on 1.6+), provided that `jruby-openssl` is also
installed. It is [continuously tested][ci] on all three of these
platforms.
+There is support for having a different adapter defined for
+JRuby. It's very similar to the DataMapper support described above: if
+you define a key called `jruby_adapter` in a configuration, it will be
+copied to `adapter` when Bcdatabase is running under JRuby. Unlike the
+DataMapper support, it is automatic — no need to specify a
+transform.
+
[ci]: https://public-ci.nubic.northwestern.edu/job/bcdatabase/
## Credits
View
@@ -120,16 +120,27 @@ class DatabaseConfigurations
},
:datamapper => lambda { |entry, name, group|
entry.merge('adapter' => entry['datamapper_adapter']) if entry['datamapper_adapter']
+ },
+ :jruby => lambda { |entry, name, group|
+ entry.merge('adapter' => entry['jruby_adapter']) if entry['jruby_adapter']
}
}
+ def self.automatic_transforms
+ @automatic_transforms ||= [
+ :key_defaults,
+ :decrypt,
+ (:jruby if RUBY_PLATFORM =~ /java/)
+ ].compact
+ end
+
##
# Creates a configuration from a set of YAML files.
#
# General use of the library should not use this method, but
# instead should use {Bcdatabase.load}.
def initialize(files, transforms=[])
- @transforms = ([:key_defaults, :decrypt] + transforms).collect do |t|
+ @transforms = (self.class.automatic_transforms + transforms).collect do |t|
case t
when Symbol
BUILT_IN_TRANSFORMS[t] or fail "No built-in transform named #{t.inspect}"
View
@@ -318,6 +318,29 @@
bcdb['foo', 'aleph']['adapter'].should == 'postgresql'
end
end
+
+ describe 'with a JRuby adapter' do
+ let(:bcdb) { Bcdatabase.load }
+
+ before do
+ temporary_yaml 'foo', {
+ 'aleph' => {
+ 'jruby_adapter' => 'jdbcpostgresql',
+ 'adapter' => 'postgresql'
+ }
+ }
+ end
+
+ if RUBY_PLATFORM =~ /java/
+ it 'uses it in JRuby' do
+ bcdb['foo', 'aleph']['adapter'].should == 'jdbcpostgresql'
+ end
+ else
+ it 'does not use it on other platforms' do
+ bcdb['foo', 'aleph']['adapter'].should == 'postgresql'
+ end
+ end
+ end
end
describe "for database.yml" do

0 comments on commit 4f86010

Please sign in to comment.