Module: Mongoid::Document::ClassMethods
- Defined in:
- lib/mongoid/document.rb
Instance Method Summary collapse
-
#===(other) ⇒ true, false
Performs class equality checking.
-
#_types ⇒ Array<Class>
Returns all types to query for when using this class as the base.
-
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
-
#instantiate(attrs = nil, criteria_instance_id = nil) {|doc| ... } ⇒ Document
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
-
#logger ⇒ Logger
Returns the logger.
Instance Method Details
#===(other) ⇒ true, false
Performs class equality checking.
295 296 297 |
# File 'lib/mongoid/document.rb', line 295 def ===(other) other.class == Class ? self <= other : other.is_a?(self) end |
#_types ⇒ Array<Class>
Returns all types to query for when using this class as the base.
333 334 335 |
# File 'lib/mongoid/document.rb', line 333 def _types @_type ||= (descendants + [ self ]).uniq.map { |t| t.to_s } end |
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
342 343 344 |
# File 'lib/mongoid/document.rb', line 342 def i18n_scope :mongoid end |
#instantiate(attrs = nil, criteria_instance_id = nil) {|doc| ... } ⇒ Document
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/mongoid/document.rb', line 312 def instantiate(attrs = nil, criteria_instance_id = nil) attributes = attrs || {} doc = allocate doc.criteria_instance_id = criteria_instance_id doc.instance_variable_set(:@attributes, attributes) doc.apply_defaults IdentityMap.set(doc) yield(doc) if block_given? doc.run_callbacks(:find) unless doc._find_callbacks.empty? doc.run_callbacks(:initialize) unless doc._initialize_callbacks.empty? doc end |