Module: Mongoid::Document::ClassMethods
- Defined in:
- lib/mongoid/document.rb
Instance Method Summary collapse
-
#_mongoid_clear_types ⇒ Object
private
Clear the @_type cache.
-
#_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
private
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
#_mongoid_clear_types ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clear the @_type cache. This is generally called when changing the discriminator key/value on a class.
316 317 318 319 |
# File 'lib/mongoid/document.rb', line 316 def _mongoid_clear_types @_type = nil superclass._mongoid_clear_types if hereditary? end |
#_types ⇒ Array<Class>
Returns all types to query for when using this class as the base.
305 306 307 |
# File 'lib/mongoid/document.rb', line 305 def _types @_type ||= (descendants + [ self ]).uniq.map(&:discriminator_value) end |
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
324 325 326 |
# File 'lib/mongoid/document.rb', line 324 def i18n_scope :mongoid end |
#instantiate(attrs = nil, selected_fields = nil) {|doc| ... } ⇒ Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/mongoid/document.rb', line 282 def instantiate(attrs = nil, selected_fields = nil) attributes = if Mongoid.legacy_attributes attrs else attrs&.to_h end || {} 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 |