Skip to content
This repository

Added JRuby support #56

Merged
merged 1 commit into from over 1 year ago

2 participants

Filip Tepper Diogo Biazus
Filip Tepper

Hey there!

Here's a little snippet to make it work with JRuby. Let me know if there's anything else I could do, thanks!

Diogo Biazus diogob merged commit c27b375 into from November 16, 2012
Diogo Biazus diogob closed this November 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 16, 2012
Filip Tepper added JRuby support 10ad513
This page is out of date. Refresh to see the latest.
4  Gemfile
@@ -2,7 +2,9 @@ source "http://rubygems.org"
2 2
 # Add dependencies required to use your gem here.
3 3
 gem 'rails'
4 4
 gem 'rake'
5  
-gem 'pg'
  5
+
  6
+gem 'pg', :platforms => :ruby
  7
+gem 'activerecord-jdbcpostgresql-adapter', :platforms => :jruby
6 8
 
7 9
 # Add dependencies to develop your gem here.
8 10
 # Include everything needed to run rake, tests, features, etc.
7  Gemfile.lock
@@ -22,6 +22,10 @@ GEM
22 22
       activesupport (= 3.2.8)
23 23
       arel (~> 3.0.2)
24 24
       tzinfo (~> 0.3.29)
  25
+    activerecord-jdbc-adapter (1.2.2.1)
  26
+    activerecord-jdbcpostgresql-adapter (1.2.2.1)
  27
+      activerecord-jdbc-adapter (~> 1.2.2.1)
  28
+      jdbc-postgres (>= 9.0, < 9.2)
25 29
     activeresource (3.2.8)
26 30
       activemodel (= 3.2.8)
27 31
       activesupport (= 3.2.8)
@@ -35,6 +39,7 @@ GEM
35 39
     git (1.2.5)
36 40
     hike (1.2.1)
37 41
     i18n (0.6.1)
  42
+    jdbc-postgres (9.1.901)
38 43
     jeweler (1.8.4)
39 44
       bundler (~> 1.0)
40 45
       git (>= 1.2.5)
@@ -101,9 +106,11 @@ GEM
101 106
     tzinfo (0.3.33)
102 107
 
103 108
 PLATFORMS
  109
+  java
104 110
   ruby
105 111
 
106 112
 DEPENDENCIES
  113
+  activerecord-jdbcpostgresql-adapter
107 114
   bundler (~> 1.1.3)
108 115
   jeweler (~> 1.8.3)
109 116
   pg
18  activerecord-postgres-hstore.gemspec
@@ -104,7 +104,11 @@ Gem::Specification.new do |s|
104 104
     if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
105 105
       s.add_runtime_dependency(%q<rails>, [">= 0"])
106 106
       s.add_runtime_dependency(%q<rake>, [">= 0"])
107  
-      s.add_runtime_dependency(%q<pg>, [">= 0"])
  107
+      if RUBY_PLATFORM == "java"
  108
+        s.add_runtime_dependency(%q<activerecord-jdbcpostgresql-adapter>, [">= 0"])
  109
+      else
  110
+        s.add_runtime_dependency(%q<pg>, [">= 0"])
  111
+      end
108 112
       s.add_development_dependency(%q<shoulda>, [">= 0"])
109 113
       s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
110 114
       s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
@@ -113,7 +117,11 @@ Gem::Specification.new do |s|
113 117
     else
114 118
       s.add_dependency(%q<rails>, [">= 0"])
115 119
       s.add_dependency(%q<rake>, [">= 0"])
116  
-      s.add_dependency(%q<pg>, [">= 0"])
  120
+      if RUBY_PLATFORM == "java"
  121
+        s.add_dependency(%q<activerecord-jdbcpostgresql-adapter>, [">= 0"])
  122
+      else
  123
+        s.add_dependency(%q<pg>, [">= 0"])
  124
+      end
117 125
       s.add_dependency(%q<shoulda>, [">= 0"])
118 126
       s.add_dependency(%q<bundler>, ["~> 1.1.3"])
119 127
       s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
@@ -123,7 +131,11 @@ Gem::Specification.new do |s|
123 131
   else
124 132
     s.add_dependency(%q<rails>, [">= 0"])
125 133
     s.add_dependency(%q<rake>, [">= 0"])
126  
-    s.add_dependency(%q<pg>, [">= 0"])
  134
+    if RUBY_PLATFORM == "java"
  135
+      s.add_dependency(%q<activerecord-jdbcpostgresql-adapter>, [">= 0"])
  136
+    else
  137
+      s.add_dependency(%q<pg>, [">= 0"])
  138
+    end
127 139
     s.add_dependency(%q<shoulda>, [">= 0"])
128 140
     s.add_dependency(%q<bundler>, ["~> 1.1.3"])
129 141
     s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
3  app/Gemfile
... ...
@@ -1,7 +1,8 @@
1 1
 source 'http://rubygems.org'
2 2
 
3 3
 gem 'rails', '3.0.0'
4  
-gem 'pg'
  4
+gem 'pg', :platforms => :ruby
  5
+gem 'activerecord-jdbcpostgresql-adapter', :platforms => :jruby
5 6
 gem 'activerecord-postgres-hstore', :path => '../'
6 7
 
7 8
 # Use unicorn as the web server
4  lib/activerecord-postgres-hstore/activerecord.rb
@@ -133,7 +133,7 @@ def hstore(*args)
133 133
 
134 134
     end
135 135
 
136  
-    class PostgreSQLColumn < Column
  136
+    class PostgreSQLColumn
137 137
       # Does the type casting from hstore columns using String#from_hstore or Hash#from_hstore.
138 138
       def type_cast_code_with_hstore(var_name)
139 139
         type == :hstore ? "#{var_name}.from_hstore" : type_cast_code_without_hstore(var_name)
@@ -148,7 +148,7 @@ def simplified_type_with_hstore(field_type)
148 148
       alias_method_chain :simplified_type, :hstore
149 149
     end
150 150
 
151  
-    class PostgreSQLAdapter < AbstractAdapter
  151
+    class PostgreSQLAdapter
152 152
       def native_database_types_with_hstore
153 153
         native_database_types_without_hstore.merge({:hstore => { :name => "hstore" }})
154 154
       end
9  lib/activerecord-postgres-hstore/railties.rb
... ...
@@ -1,14 +1,19 @@
1 1
 require 'rails'
2 2
 require 'rails/generators'
3 3
 require 'rails/generators/migration'
4  
-require 'pg'
  4
+
  5
+if RUBY_PLATFORM == "jruby"
  6
+  require 'activerecord-jdbcpostgresql-adapter'
  7
+else
  8
+  require 'pg'
  9
+end
5 10
 
6 11
 # = Hstore Railtie
7 12
 #
8 13
 # Creates a new railtie for 2 reasons:
9 14
 #
10 15
 # * Initialize ActiveRecord properly
11  
-# * Add hstore:setup generator 
  16
+# * Add hstore:setup generator
12 17
 class Hstore < Rails::Railtie
13 18
 
14 19
   initializer 'activerecord-postgres-hstore' do
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.