Skip to content

Commit

Permalink
Merge pull request jashmenn#52 from ankane/master
Browse files Browse the repository at this point in the history
Added support for ActiveRecord 4.2
  • Loading branch information
pyromaniac committed Dec 31, 2014
2 parents 3ff642e + 4eaafd4 commit 8ebad2f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gemfile:
- gemfiles/Gemfile.rails-3-1
- gemfiles/Gemfile.rails-3-2
- gemfiles/Gemfile.rails-4-0
- gemfiles/Gemfile.rails-4-1
- gemfiles/Gemfile.rails-4-2
- gemfiles/Gemfile.rails-head

env:
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/Gemfile.rails-4-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec path: '../'

gem 'activerecord', '~> 4.2.0'
52 changes: 50 additions & 2 deletions lib/activeuuid/patches.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
require 'active_record'
require 'active_support/concern'

if ActiveRecord::VERSION::MAJOR == 4 and ActiveRecord::VERSION::MINOR == 2
module ActiveRecord
module Type
class UUID < Binary # :nodoc:
def type
:uuid
end

def cast_value(value)
UUIDTools::UUID.serialize(value)
end
end
end
end

module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
class Uuid < Type::Value # :nodoc:
def type_cast_from_user(value)
UUIDTools::UUID.serialize(value) if value
end
alias_method :type_cast_from_database, :type_cast_from_user
end
end
end
end
end
end

module ActiveUUID
module Patches
Expand Down Expand Up @@ -108,12 +138,30 @@ def native_database_types_with_pguuid
end
end

module AbstractAdapter
extend ActiveSupport::Concern

included do
def initialize_type_map_with_uuid(m)
initialize_type_map_without_uuid(m)
register_class_with_limit m, /binary\(16(,0)?\)/i, ::ActiveRecord::Type::UUID
end

alias_method_chain :initialize_type_map, :uuid
end
end

def self.apply!
ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition

ActiveRecord::ConnectionAdapters::Column.send :include, Column
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send :include, PostgreSQLColumn if defined? ActiveRecord::ConnectionAdapters::PostgreSQLColumn
if ActiveRecord::VERSION::MAJOR == 4 and ActiveRecord::VERSION::MINOR == 2
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, AbstractAdapter if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, AbstractAdapter if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
else
ActiveRecord::ConnectionAdapters::Column.send :include, Column
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send :include, PostgreSQLColumn if defined? ActiveRecord::ConnectionAdapters::PostgreSQLColumn
end

ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
Expand Down

0 comments on commit 8ebad2f

Please sign in to comment.