module Antecedent

Constants

ASSOCIATION
VERSION

Public Class Methods

disable_sti() click to toggle source
# File lib/antecedent/active_record_5.rb, line 4
def self.disable_sti
  ASSOCIATION.class_eval do
    alias _klass klass

    def klass
      type = owner[reflection.foreign_type]
      type.presence && type_base_class(type)
    end

    private

    def type_base_class(type)
      type.constantize.base_class
    rescue NameError
      # if type class does not exist try
      # removing namespace
      type.deconstantize.constantize
    end
  end

  ActiveRecord::Base.inheritance_column = :_type_disabled
end
enable_sti() click to toggle source
# File lib/antecedent/active_record_5.rb, line 27
def self.enable_sti
  ASSOCIATION.class_eval do
    if defined?(_klass)
      alias klass _klass
    end
  end

  ActiveRecord::Base.inheritance_column = :type
end

Private Class Methods

raise_version_error() click to toggle source
# File lib/antecedent/fallback.rb, line 12
def self.raise_version_error
  raise Antecedent::ActiveRecordVersionNotSupported.new(
    "ActiveRecord version not supported"
  )
end

Public Instance Methods

klass() click to toggle source
# File lib/antecedent/active_record_5.rb, line 8
def klass
  type = owner[reflection.foreign_type]
  type.presence && type_base_class(type)
end
type_base_class(type) click to toggle source
# File lib/antecedent/active_record_5.rb, line 15
def type_base_class(type)
  type.constantize.base_class
rescue NameError
  # if type class does not exist try
  # removing namespace
  type.deconstantize.constantize
end