Module: Mongoid::Document
- Defined in:
- lib/mongoid/document.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongoid/document.rb', line 4 def self.included(base) base.class_eval do include ActiveSupport::Callbacks include Associations, Attributes, Commands, Observable, Validatable include InstanceMethods extend ClassMethods extend Finders # Set up the class attributes that must be available to all subclasses. # These include defaults, fields class_inheritable_accessor :defaults, :fields # The same collection is used for the entire class hierarchy. cattr_accessor :_collection, :collection_name, :embedded, :primary_key, :indexed # Set the initial values. Defaults and fields get set to a # +HashWithIndifferentAccess+ while the collection name will get set to # the demodulized class. self.collection_name = self.to_s.underscore.tableize.gsub("/", "_") self.defaults = {}.with_indifferent_access self.fields = {}.with_indifferent_access self.indexed = false attr_accessor :association_name, :_parent attr_reader :attributes, :new_record delegate :collection, :defaults, :embedded?, :fields, :primary_key, :to => :klass # Define all the callbacks that are accepted by the document. define_callbacks :before_create, :before_destroy, :before_save, :before_update, :before_validation define_callbacks :after_create, :after_destroy, :after_save, :after_update, :after_validation end end |