Module: WingedCouch::Models::API::ClassMethods

Defined in:
lib/winged_couch/models/api.rb

Overview

Class methods (syntax sugar)

Instance Method Summary collapse

Instance Method Details

#countObject

Returns total amount of 'real' (non-design) documents

in current database

Returns:

  • Fixnum


60
61
62
# File 'lib/winged_couch/models/api.rb', line 60

def count
  database.info["doc_count"] - database.design_docs['rows'].count
end

#create(attrs = {}) ⇒ WingedCouch::Model

Creates record and returns it

Parameters:

  • attrs (Hash) (defaults to: {})

    hash of attributes

Returns:


22
23
24
# File 'lib/winged_couch/models/api.rb', line 22

def create(attrs = {})
  self.new(attrs).tap(&:save)
end

#design_documentObject

Return design document with default id ('_design/winged_couch')

in current database

Returns:

  • WingedCouch::Design::Document


41
42
43
44
45
# File 'lib/winged_couch/models/api.rb', line 41

def design_document
  doc = database.design_document
  doc.save unless doc.exist?
  doc
end

#find(_id) ⇒ WingedCouch::Model

Finds record in CouchDB

Parameters:

  • _id (String)

    id of record

Returns:


32
33
34
# File 'lib/winged_couch/models/api.rb', line 32

def find(_id)
  self.new(HTTP.get(database.path.join(_id)))
end

#viewsObject

Returns array of design views in the database


51
52
53
# File 'lib/winged_couch/models/api.rb', line 51

def views
  design_document.views
end