module ActiveRecord::Core::ClassMethods

def ===(object) # :nodoc:

:nodoc:
Override the default class equality method to provide support for decorated models.
def ===(object) # :nodoc:
  object.is_a?(self)
end

def arel_table # :nodoc:

:nodoc:
Returns an instance of Arel::Table loaded with the current table name.
def arel_table # :nodoc:
  @arel_table ||= Arel::Table.new(table_name, klass: self)
end

def cached_find_by_statement(key, &block) # :nodoc:

:nodoc:
def cached_find_by_statement(key, &block) # :nodoc:
  cache = @find_by_statement_cache[connection.prepared_statements]
  cache.compute_if_absent(key) { StatementCache.create(connection, &block) }
end

def filter_attributes

Returns columns which shouldn't be exposed while calling +#inspect+.
def filter_attributes
  if defined?(@filter_attributes)
    @filter_attributes
  else
    superclass.filter_attributes
  end
end

def filter_attributes=(filter_attributes)

Specifies columns which shouldn't be exposed while calling +#inspect+.
def filter_attributes=(filter_attributes)
  @inspection_filter = nil
  @filter_attributes = filter_attributes
end

def find(*ids) # :nodoc:

:nodoc:
def find(*ids) # :nodoc:
  # We don't have cache keys for this stuff yet
  return super unless ids.length == 1
  return super if block_given? || primary_key.nil? || scope_attributes?
  id = ids.first
  return super if StatementCache.unsupported_value?(id)
  key = primary_key
  statement = cached_find_by_statement(key) { |params|
    where(key => params.bind).limit(1)
  }
  statement.execute([id], connection).first ||
    raise(RecordNotFound.new("Couldn't find #{name} with '#{key}'=#{id}", name, key, id))
end

def find_by(*args) # :nodoc:

:nodoc:
def find_by(*args) # :nodoc:
  return super if scope_attributes?
  hash = args.first
  return super unless Hash === hash
  hash = hash.each_with_object({}) do |(key, value), h|
    key = key.to_s
    key = attribute_aliases[key] || key
    return super if reflect_on_aggregation(key)
    reflection = _reflect_on_association(key)
    if !reflection
      value = value.id if value.respond_to?(:id)
    elsif reflection.belongs_to? && !reflection.polymorphic?
      key = reflection.join_foreign_key
      pkey = reflection.join_primary_key
      value = value.public_send(pkey) if value.respond_to?(pkey)
    end
    if !columns_hash.key?(key) || StatementCache.unsupported_value?(value)
      return super
    end
    h[key] = value
  end
  keys = hash.keys
  statement = cached_find_by_statement(keys) { |params|
    wheres = keys.index_with { params.bind }
    where(wheres).limit(1)
  }
  begin
    statement.execute(hash.values, connection).first
  rescue TypeError
    raise ActiveRecord::StatementInvalid
  end
end

def find_by!(*args) # :nodoc:

:nodoc:
def find_by!(*args) # :nodoc:
  find_by(*args) || where(*args).raise_record_not_found_exception!
end

def generated_association_methods # :nodoc:

:nodoc:
def generated_association_methods # :nodoc:
  @generated_association_methods ||= begin
    mod = const_set(:GeneratedAssociationMethods, Module.new)
    private_constant :GeneratedAssociationMethods
    include mod
    mod
  end
end

def inherited(child_class) # :nodoc:

:nodoc:
def inherited(child_class) # :nodoc:
  # initialize cache at class definition for thread safety
  child_class.initialize_find_by_cache
  unless child_class.base_class?
    klass = self
    until klass.base_class?
      klass.initialize_find_by_cache
      klass = klass.superclass
    end
  end
  super
end

def initialize_find_by_cache # :nodoc:

:nodoc:
def initialize_find_by_cache # :nodoc:
  @find_by_statement_cache = { true => Concurrent::Map.new, false => Concurrent::Map.new }
end

def initialize_generated_modules # :nodoc:

:nodoc:
def initialize_generated_modules # :nodoc:
  generated_association_methods
end

def inspect # :nodoc:

:nodoc:
Returns a string like 'Post(id:integer, title:string, body:text)'
def inspect # :nodoc:
  if self == Base
    super
  elsif abstract_class?
    "#{super}(abstract)"
  elsif !connected?
    "#{super} (call '#{super}.connection' to establish a connection)"
  elsif table_exists?
    attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", "
    "#{super}(#{attr_list})"
  else
    "#{super}(Table doesn't exist)"
  end
end

def inspection_filter # :nodoc:

:nodoc:
def inspection_filter # :nodoc:
  if defined?(@filter_attributes)
    @inspection_filter ||= begin
      mask = InspectionMask.new(ActiveSupport::ParameterFilter::FILTERED)
      ActiveSupport::ParameterFilter.new(@filter_attributes, mask: mask)
    end
  else
    superclass.inspection_filter
  end
end

def predicate_builder # :nodoc:

:nodoc:
def predicate_builder # :nodoc:
  @predicate_builder ||= PredicateBuilder.new(table_metadata)
end

def relation

def relation
  relation = Relation.create(self)
  if finder_needs_type_condition? && !ignore_default_scope?
    relation.where!(type_condition)
  else
    relation
  end
end

def table_metadata

def table_metadata
  TableMetadata.new(self, arel_table)
end

def type_caster # :nodoc:

:nodoc:
def type_caster # :nodoc:
  TypeCaster::Map.new(self)
end