Module: Mongoid::Traversable::ClassMethods
- Defined in:
- lib/mongoid/traversable.rb
Overview
Instance Method Summary collapse
-
#hereditary? ⇒ true, false
Determines if the document is a subclass of another document.
-
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behavior of the old class_inheritable_accessor that was deprecated in Rails edge.
Instance Method Details
#hereditary? ⇒ true, false
Determines if the document is a subclass of another document.
282 283 284 |
# File 'lib/mongoid/traversable.rb', line 282 def hereditary? !!(Mongoid::Document > superclass) end |
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behavior of the old class_inheritable_accessor that was deprecated in Rails edge.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/mongoid/traversable.rb', line 296 def inherited(subclass) super @_type = nil subclass.aliased_fields = aliased_fields.dup subclass.localized_fields = localized_fields.dup subclass.fields = fields.dup subclass.pre_processed_defaults = pre_processed_defaults.dup subclass.post_processed_defaults = post_processed_defaults.dup subclass._declared_scopes = Hash.new { |hash,key| self._declared_scopes[key] } subclass.discriminator_value = subclass.name # We need to do this here because the discriminator_value method is # overriden in the subclass above. class << subclass include DiscriminatorRetrieval end # We only need the _type field if inheritance is in play, but need to # add to the root class as well for backwards compatibility. unless fields.has_key?(self.discriminator_key) default_proc = lambda { self.class.discriminator_value } field(self.discriminator_key, default: default_proc, type: String) end end |