Module: Mongoid::Document::ClassMethods
- Defined in:
- build/mongoid-6.1/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, selected_fields = 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.
307 308 309 |
# File 'build/mongoid-6.1/lib/mongoid/document.rb', line 307 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.
344 345 346 |
# File 'build/mongoid-6.1/lib/mongoid/document.rb', line 344 def _types @_type ||= (descendants + [ self ]).uniq.map(&:to_s) end |
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
353 354 355 |
# File 'build/mongoid-6.1/lib/mongoid/document.rb', line 353 def i18n_scope :mongoid end |
#instantiate(attrs = nil, selected_fields = nil) {|doc| ... } ⇒ Document
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
324 325 326 327 328 329 330 331 332 333 334 |
# File 'build/mongoid-6.1/lib/mongoid/document.rb', line 324 def instantiate(attrs = nil, selected_fields = nil) attributes = attrs || {} doc = allocate doc.__selected_fields = selected_fields doc.instance_variable_set(:@attributes, attributes) doc.apply_defaults 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 |