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::Tableloaded with the current table name. - #generated_feature_methods ⇒ Object
-
#inherited(child_class) ⇒ Object
:nodoc:.
- #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.
135 136 137 |
# File 'lib/active_record/core.rb', line 135 def ===(object) object.is_a?(self) end |
#arel_engine ⇒ Object
Returns the Arel engine.
149 150 151 152 153 154 155 156 157 |
# File 'lib/active_record/core.rb', line 149 def arel_engine @arel_engine ||= begin if Base == self || connection_handler.retrieve_connection_pool(self) self else superclass.arel_engine end 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
144 145 146 |
# File 'lib/active_record/core.rb', line 144 def arel_table @arel_table ||= Arel::Table.new(table_name, arel_engine) end |
#generated_feature_methods ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/active_record/core.rb', line 112 def generated_feature_methods @generated_feature_methods ||= begin mod = const_set(:GeneratedFeatureMethods, Module.new) include mod mod end end |
#inherited(child_class) ⇒ Object
:nodoc:
94 95 96 97 |
# File 'lib/active_record/core.rb', line 94 def inherited(child_class) #:nodoc: child_class.initialize_generated_modules super end |
#initialize_generated_modules ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_record/core.rb', line 99 def initialize_generated_modules @attribute_methods_mutex = Mutex.new # force attribute methods to be higher in inheritance hierarchy than other generated methods generated_attribute_methods.const_set(:AttrNames, Module.new { def self.const_missing(name) const_set(name, [name.to_s.sub(/ATTR_/, '')].pack('h*').freeze) end }) generated_feature_methods end |
#inspect ⇒ Object
Returns a string like ‘Post(id:integer, title:string, body:text)’
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/active_record/core.rb', line 121 def inspect if self == Base super elsif abstract_class? "#{super}(abstract)" elsif table_exists? attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', ' "#{super}(#{attr_list})" else "#{super}(Table doesn't exist)" end end |