Module: ActiveRecord::Core::ClassMethods
- Defined in:
- lib/active_record/core.rb
Instance Method Summary collapse
-
#===(object) ⇒ Object
Overwrite the default class equality method to provide support for association proxies.
-
#arel_engine ⇒ Object
Returns the Arel engine.
-
#arel_table ⇒ Object
Returns an instance of
Arel::Table
loaded with the current table name. - #generated_association_methods ⇒ Object
- #initialize_generated_modules ⇒ Object
-
#inspect ⇒ Object
Returns a string like ‘Post(id:integer, title:string, body:text)’.
Instance Method Details
#===(object) ⇒ Object
Overwrite the default class equality method to provide support for association proxies.
141 142 143 |
# File 'lib/active_record/core.rb', line 141 def ===(object) object.is_a?(self) end |
#arel_engine ⇒ Object
Returns the Arel engine.
155 156 157 158 159 160 161 162 |
# File 'lib/active_record/core.rb', line 155 def arel_engine # :nodoc: @arel_engine ||= if Base == self || connection_handler.retrieve_connection_pool(self) self else superclass.arel_engine end end |
#arel_table ⇒ Object
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
150 151 152 |
# File 'lib/active_record/core.rb', line 150 def arel_table # :nodoc: @arel_table ||= Arel::Table.new(table_name, arel_engine) end |
#generated_association_methods ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/active_record/core.rb', line 116 def generated_association_methods @generated_association_methods ||= begin mod = const_set(:GeneratedAssociationMethods, Module.new) include mod mod end end |
#initialize_generated_modules ⇒ Object
110 111 112 113 114 |
# File 'lib/active_record/core.rb', line 110 def initialize_generated_modules super generated_association_methods end |
#inspect ⇒ Object
Returns a string like ‘Post(id:integer, title:string, body:text)’
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/active_record/core.rb', line 125 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 |