Skip to content

Commit

Permalink
Merge pull request #15 from pyromaniac/master
Browse files Browse the repository at this point in the history
Full activerecord >= 3.1 compatible
  • Loading branch information
jashmenn committed Oct 10, 2012
2 parents 70f8c4e + 1a2d684 commit 66c7bfb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
35 changes: 35 additions & 0 deletions .travis.yml
@@ -0,0 +1,35 @@
before_script:
- mysql -e 'create database activeuuid_test;'
- psql -c 'create database activeuuid_test;' -U postgres

rvm:
- 1.9.2
- 1.9.3
#- ruby-head
#- rbx-19mode

env:
- RAILS_VERSION='~>3.1.0'
- RAILS_VERSION='~>3.1.0' DB=mysql
- RAILS_VERSION='~>3.1.0' DB=postgresql
- RAILS_VERSION='~>3.2.0'
- RAILS_VERSION='~>3.2.0' DB=mysql
- RAILS_VERSION='~>3.2.0' DB=postgresql
- RAILS_VERSION=3-1-stable
- RAILS_VERSION=3-1-stable DB=mysql
- RAILS_VERSION=3-1-stable DB=postgresql
- RAILS_VERSION=3-2-stable
- RAILS_VERSION=3-2-stable DB=mysql
- RAILS_VERSION=3-2-stable DB=postgresql
- RAILS_VERSION=master
- RAILS_VERSION=master DB=mysql
- RAILS_VERSION=master DB=postgresql

matrix:
exclude:
- rvm: 1.9.2
env: RAILS_VERSION=master
- rvm: 1.9.2
env: RAILS_VERSION=master DB=mysql
- rvm: 1.9.2
env: RAILS_VERSION=master DB=postgresql
11 changes: 11 additions & 0 deletions Gemfile
Expand Up @@ -2,3 +2,14 @@ source "http://rubygems.org"


# Specify your gem's dependencies in activeuuid.gemspec # Specify your gem's dependencies in activeuuid.gemspec
gemspec gemspec

case version = ENV['ACTIVERECORD_VERSION'] || '~> 3.2'
when /master/
gem "activerecord", :github => "rails/rails"
when /3-1-stable/
gem "activerecord", :github => "rails/rails", :branch => "3-1-stable"
when /3-2-stable/
gem "activerecord", :github => "rails/rails", :branch => "3-2-stable"
else
gem "activerecord", version
end
2 changes: 1 addition & 1 deletion lib/activeuuid/patches.rb
Expand Up @@ -52,7 +52,7 @@ def type_cast_with_visiting(value, column = nil)
def self.apply! def self.apply!
ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, PostgreSQLQuoting if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, PostgreSQLQuoting if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
end end
Expand Down
7 changes: 5 additions & 2 deletions lib/activeuuid/uuid.rb
@@ -1,8 +1,8 @@
require 'uuidtools' require 'uuidtools'


# monkey-patch Friendly::UUID to serialize UUIDs
module UUIDTools module UUIDTools
class UUID class UUID
# monkey-patch Friendly::UUID to serialize UUIDs to MySQL
alias_method :id, :raw alias_method :id, :raw


def quoted_id def quoted_id
Expand All @@ -17,6 +17,9 @@ def as_json(options = nil)
def to_param def to_param
hexdigest.upcase hexdigest.upcase
end end

# duck typing activerecord 3.1 dirty hack )
def gsub *; self; end
end end
end end


Expand Down Expand Up @@ -75,7 +78,7 @@ def dump(uuid)
private private


def parse_string str def parse_string str
return nil if str.blank? return nil if str.length == 0
if str.length == 36 if str.length == 36
UUIDTools::UUID.parse str UUIDTools::UUID.parse str
elsif str.length == 32 elsif str.length == 32
Expand Down
7 changes: 2 additions & 5 deletions spec/support/database.yml
Expand Up @@ -4,12 +4,9 @@ sqlite3:
postgresql: postgresql:
adapter: postgresql adapter: postgresql
username: postgres username: postgres
password:
database: activeuuid_test database: activeuuid_test
min_messages: ERROR
mysql: mysql:
adapter: mysql2 adapter: mysql2
host: localhost
username: root username: root
password: database: activeuuid_test
database: activeuuid_test encoding: utf8

0 comments on commit 66c7bfb

Please sign in to comment.