Module: CouchSurfer::Model

Defined in:
lib/couch_surfer/model.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.default_databaseObject



10
11
12
# File 'lib/couch_surfer/model.rb', line 10

def self.default_database
  @database
end

.default_database=(db) ⇒ Object



14
15
16
# File 'lib/couch_surfer/model.rb', line 14

def self.default_database= db
  @database = db
end

.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