Module: ActiveRecord::Core::ClassMethods

Defined in:
activerecord/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.



122
123
124
# File 'activerecord/lib/active_record/core.rb', line 122

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

#arel_engineObject

Returns the Arel engine.



136
137
138
139
140
141
142
143
144
# File 'activerecord/lib/active_record/core.rb', line 136

def arel_engine
  @arel_engine ||= begin
    if Base == self || connection_handler.retrieve_connection_pool(self)
      self
    else
      superclass.arel_engine
    end
  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


131
132
133
# File 'activerecord/lib/active_record/core.rb', line 131

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

#generated_feature_methodsObject



97
98
99
100
101
102
103
# File 'activerecord/lib/active_record/core.rb', line 97

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

#initialize_generated_modulesObject



91
92
93
94
95
# File 'activerecord/lib/active_record/core.rb', line 91

def initialize_generated_modules
  super

  generated_feature_methods
end

#inspectObject

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'activerecord/lib/active_record/core.rb', line 106

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