Class: WingedCouch::Model

Inherits:
Object
  • Object
show all
Extended by:
WingedCouch::Models::Bulk, WingedCouch::Models::Queries
Includes:
ActiveModel::Model, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml, WingedCouch::Models::API, WingedCouch::Models::Attributes, WingedCouch::Models::Hooks, WingedCouch::Models::Persistence, WingedCouch::Models::Validation
Defined in:
lib/winged_couch/model.rb

Overview

Main model class

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WingedCouch::Models::Bulk

bulk, bulk?, bulk_records

Methods included from WingedCouch::Models::Queries

view

Methods included from WingedCouch::Models::Hooks

included

Methods included from WingedCouch::Models::Validation

#errors, included

Methods included from WingedCouch::Models::API

#==, included, #initialize, #inspect, #with, #with!

Methods included from WingedCouch::Models::Persistence

#delete, included, #persisted?, #save, #update

Methods included from WingedCouch::Models::Attributes

included, #native_document

Class Method Details

.has_active_model?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/winged_couch/model.rb', line 33

def self.has_active_model?
  true
end

.inherited(klass) ⇒ Object


50
51
52
53
# File 'lib/winged_couch/model.rb', line 50

def self.inherited(klass)
  super
  klass.upload_views!
end

.upload_views!Object


55
56
57
58
59
60
61
# File 'lib/winged_couch/model.rb', line 55

def self.upload_views!
  begin
    ViewsLoader.upload_views_for(self)
  rescue WingedCouch::Exceptions::ViewsMissing => e
    WingedCouch.logger.debug("Can't upload views for #{self.name}.")
  end
end

Instance Method Details

#as_json(options = nil) ⇒ Object


25
26
27
# File 'lib/winged_couch/model.rb', line 25

def as_json(options = nil)
  serializable_hash(options)
end

#attributesObject


29
30
31
# File 'lib/winged_couch/model.rb', line 29

def attributes
  super.merge(_id: _id, _rev: _rev).stringify_keys
end

#to_keyObject


21
22
23
# File 'lib/winged_couch/model.rb', line 21

def to_key
  [_id]
end