Sha256: cf943dba84e31692e5029062719afc97210916a152ebd984a12719c35cc25f6d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module HasUuid
  class Railtie < Rails::Railtie
    initializer 'has_uuid' do |app|
      ActiveSupport.on_load :active_record do
        ::ActiveRecord::Relation.send :include, HasUuid::ActiveRecord::FinderMethods
        ::ActiveRecord::Reflection::AssociationReflection.send :include, HasUuid::ActiveRecord::Reflection::AssociationReflection
        ::ActiveRecord::Associations::BelongsToAssociation.send :include, HasUuid::ActiveRecord::BelongsToAssociation
        ::ActiveRecord::Associations::SingularAssociation.send :include, HasUuid::ActiveRecord::Associations::SingularAssociation
        ::ActiveRecord::Associations::CollectionAssociation.send :include, HasUuid::ActiveRecord::Associations::CollectionAssociation
        ::ActiveRecord::Associations::Builder::SingularAssociation.send :include, HasUuid::ActiveRecord::Associations::Builder::SingularAssociation
        ::ActiveRecord::Associations::Builder::CollectionAssociation.send :include, HasUuid::ActiveRecord::Associations::Builder::CollectionAssociation
        ::ActiveRecord::Base.send :include, HasUuid
      end

      ActiveSupport.on_load :activeuuid do
        # We don't want our ids to be UUIDs so override activeuuid's implementation
        ::ActiveRecord::ConnectionAdapters::Table.send :include, HasUuid::ActiveRecord::ConnectionAdapters::Migrations if defined? ActiveRecord::ConnectionAdapters::Table
        ::ActiveRecord::ConnectionAdapters::TableDefinition.send :include, HasUuid::ActiveRecord::ConnectionAdapters::Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_has_uuid-0.2.0 lib/has_uuid/railtie.rb