Method: CouchSurfer::Model.included

Defined in:
lib/couch_surfer/model.rb

.included(receiver) ⇒ Object



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/couch_surfer/model.rb', line 647

def self.included(receiver)
  receiver.extend         ClassMethods
  receiver.send :include, InstanceMethods
  receiver.class_eval do

    attr_reader :attributes
    cattr_accessor :default_database
    class_inheritable_accessor :class_database
    class_inheritable_accessor :default_obj
    class_inheritable_accessor :casts
    class_inheritable_accessor :design_doc
    class_inheritable_accessor :design_doc_slug_cache
    class_inheritable_accessor :design_doc_fresh

    alias :new_record? :new_document?
    def initialize attrs = {}
      @attributes = CouchRest::Document.new(attrs)
      apply_defaults
      cast_keys
      unless self['_id'] && self['_rev']
        @attributes['couchrest-type'] = self.class.to_s
      end
    end

    include ::Extlib::Hook
    register_instance_hooks :save, :create, :update, :destroy
  end
end