Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

JRuby support

  • Loading branch information...
commit 5919c4cee1ae73ba5164a1e114e65aef20d086f9 1 parent 2ce211d
Tim Morgan authored
5 Gemfile
@@ -13,5 +13,6 @@ group :development do
13 13 # TEST
14 14 gem 'rspec'
15 15 gem 'factory_girl'
16   - gem 'pg'
17   -end
  16 + platform(:mri) { gem 'pg' }
  17 + platform(:jruby) { gem 'activerecord-jdbcpostgresql-adapter' }
  18 +end
66 Gemfile.lock
... ... @@ -1,50 +1,62 @@
1 1 GEM
2 2 remote: http://rubygems.org/
3 3 specs:
4   - RedCloth (4.2.8)
5   - activemodel (3.1.0)
6   - activesupport (= 3.1.0)
7   - bcrypt-ruby (~> 3.0.0)
  4 + RedCloth (4.2.9)
  5 + RedCloth (4.2.9-java)
  6 + activemodel (3.2.3)
  7 + activesupport (= 3.2.3)
8 8 builder (~> 3.0.0)
9   - i18n (~> 0.6)
10   - activerecord (3.1.0)
11   - activemodel (= 3.1.0)
12   - activesupport (= 3.1.0)
13   - arel (~> 2.2.1)
  9 + activerecord (3.2.3)
  10 + activemodel (= 3.2.3)
  11 + activesupport (= 3.2.3)
  12 + arel (~> 3.0.2)
14 13 tzinfo (~> 0.3.29)
15   - activesupport (3.1.0)
  14 + activerecord-jdbc-adapter (1.2.2)
  15 + activerecord-jdbcpostgresql-adapter (1.2.2)
  16 + activerecord-jdbc-adapter (~> 1.2.2)
  17 + jdbc-postgres (>= 9.0, < 9.2)
  18 + activesupport (3.2.3)
  19 + i18n (~> 0.6)
16 20 multi_json (~> 1.0)
17   - arel (2.2.1)
18   - bcrypt-ruby (3.0.0)
  21 + arel (3.0.2)
19 22 builder (3.0.0)
20 23 diff-lcs (1.1.3)
21   - factory_girl (2.0.5)
  24 + factory_girl (3.3.0)
  25 + activesupport (>= 3.0.0)
22 26 git (1.2.5)
23 27 i18n (0.6.0)
24   - jeweler (1.6.4)
  28 + jdbc-postgres (9.1.901)
  29 + jeweler (1.8.3)
25 30 bundler (~> 1.0)
26 31 git (>= 1.2.5)
27 32 rake
28   - multi_json (1.0.3)
29   - pg (0.11.0)
30   - rake (0.9.2)
31   - rspec (2.6.0)
32   - rspec-core (~> 2.6.0)
33   - rspec-expectations (~> 2.6.0)
34   - rspec-mocks (~> 2.6.0)
35   - rspec-core (2.6.4)
36   - rspec-expectations (2.6.0)
37   - diff-lcs (~> 1.1.2)
38   - rspec-mocks (2.6.0)
39   - tzinfo (0.3.29)
40   - yard (0.7.2)
  33 + rdoc
  34 + json (1.7.3)
  35 + json (1.7.3-java)
  36 + multi_json (1.3.5)
  37 + pg (0.13.2)
  38 + rake (0.9.2.2)
  39 + rdoc (3.12)
  40 + json (~> 1.4)
  41 + rspec (2.10.0)
  42 + rspec-core (~> 2.10.0)
  43 + rspec-expectations (~> 2.10.0)
  44 + rspec-mocks (~> 2.10.0)
  45 + rspec-core (2.10.0)
  46 + rspec-expectations (2.10.0)
  47 + diff-lcs (~> 1.1.3)
  48 + rspec-mocks (2.10.1)
  49 + tzinfo (0.3.33)
  50 + yard (0.8.1)
41 51
42 52 PLATFORMS
  53 + java
43 54 ruby
44 55
45 56 DEPENDENCIES
46 57 RedCloth
47 58 activerecord (>= 3.0)
  59 + activerecord-jdbcpostgresql-adapter
48 60 activesupport (>= 3.0)
49 61 factory_girl
50 62 jeweler
23 lib/enum_type/extensions.rb
@@ -7,7 +7,7 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLColumn
7 7 def initialize(name, default, sql_type = nil, null = true)
8 8 super(name, self.class.extract_value_from_default(default, sql_type), sql_type, null)
9 9 end
10   -
  10 +
11 11 def self.extract_value_from_default_with_enum(default, type)
12 12 case default
13 13 when /\A'(.*)'::(?:#{Regexp.escape type})\z/
@@ -16,8 +16,25 @@ def self.extract_value_from_default_with_enum(default, type)
16 16 extract_value_from_default_without_enum default
17 17 end
18 18 end
19   -
  19 +
20 20 class << self
21 21 alias_method_chain :extract_value_from_default, :enum
22 22 end
23   -end
  23 +end if ActiveRecord::ConnectionAdapters::PostgreSQLColumn.methods.include?(:extract_value_from_default)
  24 +
  25 +class ActiveRecord::ConnectionAdapters::JdbcColumn
  26 + def initialize(config, name, default, *args)
  27 + call_discovered_column_callbacks(config)
  28 + super(name,enum_default_value(default, args.first),*args)
  29 + init_column(name, default, *args)
  30 + end
  31 +
  32 + def enum_default_value(default, type)
  33 + case default
  34 + when /\A'(.*)'::(?:#{Regexp.escape type})\z/
  35 + $1
  36 + else
  37 + default_value default
  38 + end
  39 + end
  40 +end if defined?(ActiveRecord::ConnectionAdapters::JdbcColumn)
2  spec/spec_helper.rb
@@ -7,7 +7,7 @@
7 7 require 'enum_type'
8 8
9 9 ActiveRecord::Base.establish_connection(
10   - adapter: 'postgresql',
  10 + adapter: (defined?(JRuby) ? 'jdbcpostgresql' : 'postgresql'),
11 11 database: 'enum_type_test',
12 12 username: 'enum_type_tester'
13 13 )

0 comments on commit 5919c4c

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