Class: WingedCouch::Design::Document

Inherits:
Native::Document show all
Defined in:
lib/winged_couch/design/document.rb

Overview

Class for working with design documents.

Constant Summary collapse

DEFAULT_DOCUMENT_ID =

Default id of design document

"_design/winged_couch"

Instance Attribute Summary

Attributes inherited from Abstract::Document

#data, #database

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Native::Document

#delete, #errors, #fetch_revision!, find, #reload, #save, #update

Methods inherited from Abstract::Document

#==, #_id, #_id=, #_rev, #_rev=, #inspect

Constructor Details

#initialize(database, data = {}) ⇒ Document

Returns a new instance of Document

Parameters:


15
16
17
# File 'lib/winged_couch/design/document.rb', line 15

def initialize(database, data = {})
  super(database, data.merge(_id: DEFAULT_DOCUMENT_ID))
end

Class Method Details

.from(database) ⇒ Object

Returns design document from passed database

Parameters:

Returns:

  • WingedCouch::Design::Document


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

def self.from(database)
  new(database).reload
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)

47
48
49
50
51
# File 'lib/winged_couch/design/document.rb', line 47

def exist?
  super
rescue Exceptions::NoDesignDocument
  false
end

#pathObject

Returns document's database path with corresponding level

Returns:

  • WingedCouch::HttpPath


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

def path
  database.path.join(_id, :design_document)
end

#viewsObject

Returns all views specified in design document


41
42
43
44
45
# File 'lib/winged_couch/design/document.rb', line 41

def views
  data.fetch(:views, {}).map do |view_name, _|
    Design::View.from(self, view_name)
  end
end