Skip to content
Browse files

JRuby support

  • Loading branch information...
1 parent 2ce211d commit 5919c4cee1ae73ba5164a1e114e65aef20d086f9 @RISCfuture committed May 14, 2012
Showing with 63 additions and 33 deletions.
  1. +3 −2 Gemfile
  2. +39 −27 Gemfile.lock
  3. +20 −3 lib/enum_type/extensions.rb
  4. +1 −1 spec/spec_helper.rb
View
5 Gemfile
@@ -13,5 +13,6 @@ group :development do
# TEST
gem 'rspec'
gem 'factory_girl'
- gem 'pg'
-end
+ platform(:mri) { gem 'pg' }
+ platform(:jruby) { gem 'activerecord-jdbcpostgresql-adapter' }
+end
View
66 Gemfile.lock
@@ -1,50 +1,62 @@
GEM
remote: http://rubygems.org/
specs:
- RedCloth (4.2.8)
- activemodel (3.1.0)
- activesupport (= 3.1.0)
- bcrypt-ruby (~> 3.0.0)
+ RedCloth (4.2.9)
+ RedCloth (4.2.9-java)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.0)
- activemodel (= 3.1.0)
- activesupport (= 3.1.0)
- arel (~> 2.2.1)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activesupport (3.1.0)
+ activerecord-jdbc-adapter (1.2.2)
+ activerecord-jdbcpostgresql-adapter (1.2.2)
+ activerecord-jdbc-adapter (~> 1.2.2)
+ jdbc-postgres (>= 9.0, < 9.2)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
multi_json (~> 1.0)
- arel (2.2.1)
- bcrypt-ruby (3.0.0)
+ arel (3.0.2)
builder (3.0.0)
diff-lcs (1.1.3)
- factory_girl (2.0.5)
+ factory_girl (3.3.0)
+ activesupport (>= 3.0.0)
git (1.2.5)
i18n (0.6.0)
- jeweler (1.6.4)
+ jdbc-postgres (9.1.901)
+ jeweler (1.8.3)
bundler (~> 1.0)
git (>= 1.2.5)
rake
- multi_json (1.0.3)
- pg (0.11.0)
- rake (0.9.2)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.4)
- rspec-expectations (2.6.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.6.0)
- tzinfo (0.3.29)
- yard (0.7.2)
+ rdoc
+ json (1.7.3)
+ json (1.7.3-java)
+ multi_json (1.3.5)
+ pg (0.13.2)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.10.0)
+ rspec-core (~> 2.10.0)
+ rspec-expectations (~> 2.10.0)
+ rspec-mocks (~> 2.10.0)
+ rspec-core (2.10.0)
+ rspec-expectations (2.10.0)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.10.1)
+ tzinfo (0.3.33)
+ yard (0.8.1)
PLATFORMS
+ java
ruby
DEPENDENCIES
RedCloth
activerecord (>= 3.0)
+ activerecord-jdbcpostgresql-adapter
activesupport (>= 3.0)
factory_girl
jeweler
View
23 lib/enum_type/extensions.rb
@@ -7,7 +7,7 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLColumn
def initialize(name, default, sql_type = nil, null = true)
super(name, self.class.extract_value_from_default(default, sql_type), sql_type, null)
end
-
+
def self.extract_value_from_default_with_enum(default, type)
case default
when /\A'(.*)'::(?:#{Regexp.escape type})\z/
@@ -16,8 +16,25 @@ def self.extract_value_from_default_with_enum(default, type)
extract_value_from_default_without_enum default
end
end
-
+
class << self
alias_method_chain :extract_value_from_default, :enum
end
-end
+end if ActiveRecord::ConnectionAdapters::PostgreSQLColumn.methods.include?(:extract_value_from_default)
+
+class ActiveRecord::ConnectionAdapters::JdbcColumn
+ def initialize(config, name, default, *args)
+ call_discovered_column_callbacks(config)
+ super(name,enum_default_value(default, args.first),*args)
+ init_column(name, default, *args)
+ end
+
+ def enum_default_value(default, type)
+ case default
+ when /\A'(.*)'::(?:#{Regexp.escape type})\z/
+ $1
+ else
+ default_value default
+ end
+ end
+end if defined?(ActiveRecord::ConnectionAdapters::JdbcColumn)
View
2 spec/spec_helper.rb
@@ -7,7 +7,7 @@
require 'enum_type'
ActiveRecord::Base.establish_connection(
- adapter: 'postgresql',
+ adapter: (defined?(JRuby) ? 'jdbcpostgresql' : 'postgresql'),
database: 'enum_type_test',
username: 'enum_type_tester'
)

0 comments on commit 5919c4c

Please sign in to comment.
Something went wrong with that request. Please try again.