diff --git a/Gemfile b/Gemfile index 5562177..9607a9c 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,5 @@ source "http://rubygems.org" # Specify your gem's dependencies in activeuuid.gemspec gemspec - -gem "activerecord" +gem 'rake', '< 11.0' +gem "activerecord", "~>5.0" diff --git a/lib/activeuuid/patches.rb b/lib/activeuuid/patches.rb index a29b363..84b1591 100644 --- a/lib/activeuuid/patches.rb +++ b/lib/activeuuid/patches.rb @@ -2,7 +2,7 @@ require 'active_support/concern' if (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2) || - (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0) + (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0) module ActiveRecord module Type class UUID < Binary # :nodoc: @@ -52,25 +52,21 @@ def uuid(*column_names) module Column extend ActiveSupport::Concern - included do + def self.prepended(klass) def type_cast_with_uuid(value) return UUIDTools::UUID.serialize(value) if type == :uuid - type_cast_without_uuid(value) + super end def type_cast_code_with_uuid(var_name) return "UUIDTools::UUID.serialize(#{var_name})" if type == :uuid - type_cast_code_without_uuid(var_name) + super end def simplified_type_with_uuid(field_type) return :uuid if field_type == 'binary(16)' || field_type == 'binary(16,0)' - simplified_type_without_uuid(field_type) + super end - - alias_method_chain :type_cast, :uuid - alias_method_chain :type_cast_code, :uuid if ActiveRecord::VERSION::MAJOR < 4 - alias_method_chain :simplified_type, :uuid end end @@ -103,69 +99,59 @@ def simplified_type(field_type) module PostgreSQLColumn extend ActiveSupport::Concern - included do + def self.prepended(klass) def type_cast_with_uuid(value) return UUIDTools::UUID.serialize(value) if type == :uuid - type_cast_without_uuid(value) + super end alias_method_chain :type_cast, :uuid if ActiveRecord::VERSION::MAJOR >= 4 def simplified_type_with_pguuid(field_type) return :uuid if field_type == 'uuid' - simplified_type_without_pguuid(field_type) + super end - - alias_method_chain :simplified_type, :pguuid end end module Quoting extend ActiveSupport::Concern - included do + def self.prepended(klass) def quote_with_visiting(value, column = nil) value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid - quote_without_visiting(value, column) + super end def type_cast_with_visiting(value, column = nil) value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid - type_cast_without_visiting(value, column) + super end def native_database_types_with_uuid @native_database_types ||= native_database_types_without_uuid.merge(uuid: { name: 'binary', limit: 16 }) end - - alias_method_chain :quote, :visiting - alias_method_chain :type_cast, :visiting - alias_method_chain :native_database_types, :uuid end end module PostgreSQLQuoting extend ActiveSupport::Concern - included do + def self.prepended(klass) def quote_with_visiting(value, column = nil) value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid value = value.to_s if value.is_a? UUIDTools::UUID - quote_without_visiting(value, column) + super end def type_cast_with_visiting(value, column = nil, *args) value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid value = value.to_s if value.is_a? UUIDTools::UUID - type_cast_without_visiting(value, column, *args) + super end def native_database_types_with_pguuid @native_database_types ||= native_database_types_without_pguuid.merge(uuid: { name: 'uuid' }) end - - alias_method_chain :quote, :visiting - alias_method_chain :type_cast, :visiting - alias_method_chain :native_database_types, :pguuid end end @@ -225,4 +211,4 @@ def self.apply! ActiveRecord::Base.singleton_class.prepend ConnectionHandling end end -end +end \ No newline at end of file