Module: ActiveRecord::Core::ClassMethods

Defined in:
lib/active_record/core.rb

Instance Method Summary collapse

Instance Method Details

#===(object) ⇒ Object

Overwrite the default class equality method to provide support for association proxies.



138
139
140
# File 'lib/active_record/core.rb', line 138

def ===(object)
  object.is_a?(self)
end

#arel_engineObject

Returns the Arel engine.



152
153
154
155
156
157
158
159
# File 'lib/active_record/core.rb', line 152

def arel_engine # :nodoc:
  @arel_engine ||=
    if Base == self || connection_handler.retrieve_connection_pool(self)
      self
    else
      superclass.arel_engine
    end
end

#arel_tableObject

Returns an instance of Arel::Table loaded with the current table name.

class Post < ActiveRecord::Base
  scope :published_and_commented, -> { published.and(self.arel_table[:comments_count].gt(0)) }
end


147
148
149
# File 'lib/active_record/core.rb', line 147

def arel_table # :nodoc:
  @arel_table ||= Arel::Table.new(table_name, arel_engine)
end

#generated_association_methodsObject



113
114
115
116
117
118
119
# File 'lib/active_record/core.rb', line 113

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

#initialize_generated_modulesObject



109
110
111
# File 'lib/active_record/core.rb', line 109

def initialize_generated_modules
  generated_association_methods
end

#inspectObject

Returns a string like ‘Post(id:integer, title:string, body:text)’



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/active_record/core.rb', line 122

def inspect
  if self == Base
    super
  elsif abstract_class?
    "#{super}(abstract)"
  elsif !connected?
    "#{super} (call '#{super}.connection' to establish a connection)"
  elsif table_exists?
    attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', '
    "#{super}(#{attr_list})"
  else
    "#{super}(Table doesn't exist)"
  end
end