Module: Mongoid::Document::ClassMethods
- Defined in:
- build/mongoid-master/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.
-
#construct_document(attrs = nil, execute_callbacks: true) ⇒ Document
private
Allocates and constructs a document.
-
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
-
#instantiate(attrs = nil, selected_fields = nil, &block) ⇒ Document
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
-
#instantiate_document(attrs = nil, selected_fields = nil, execute_callbacks: true) ⇒ Document
private
Instantiate the document.
-
#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.
361 362 363 364 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 361 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.
350 351 352 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 350 def _types @_type ||= (descendants + [ self ]).uniq.map(&:discriminator_value) end |
#construct_document(attrs = nil, execute_callbacks: true) ⇒ 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.
Allocates and constructs a document.
339 340 341 342 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 339 def construct_document(attrs = nil, execute_callbacks: true) doc = allocate doc.send(:construct_document, attrs, execute_callbacks: execute_callbacks) end |
#i18n_scope ⇒ Symbol
Set the i18n scope to overwrite ActiveModel.
369 370 371 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 369 def i18n_scope :mongoid end |
#instantiate(attrs = nil, selected_fields = nil, &block) ⇒ Document
Instantiate a new object, only when loaded from the database or when the attributes have already been typecast.
296 297 298 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 296 def instantiate(attrs = nil, selected_fields = nil, &block) instantiate_document(attrs, selected_fields, execute_callbacks: true, &block) end |
#instantiate_document(attrs = nil, selected_fields = nil, execute_callbacks: true) ⇒ 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 the document.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'build/mongoid-master/lib/mongoid/document.rb', line 311 def instantiate_document(attrs = nil, selected_fields = nil, execute_callbacks: true) attributes = attrs || {} doc = allocate doc.__selected_fields = selected_fields doc.instance_variable_set(:@attributes, attributes) if execute_callbacks 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? else yield(doc) if block_given? doc.pending_callbacks += [:apply_defaults, :find, :initialize] end doc end |