Class: Couch::DesignDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/couch/design_document.rb

Constant Summary collapse

EXT_MIME_MAPPING =
{
  ".html" => "text/html",
  ".js" => "text/javascript",
  ".css" => "text/css",
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ DesignDocument

initialize with a hash



12
13
14
# File 'lib/couch/design_document.rb', line 12

def initialize(hash = {})
  @hash = hash
end

Class Method Details

.build_from_filesystem(root) ⇒ Object

returns new design document object from filesystem



38
39
40
# File 'lib/couch/design_document.rb', line 38

def build_from_filesystem(root)
  new map(root)
end

.build_from_json(json) ⇒ Object

returns new design document object from json string



43
44
45
# File 'lib/couch/design_document.rb', line 43

def build_from_json(json)
  new reject_makros(JSON.parse(json))
end

.databaseObject

returns the database used to store design document



48
49
50
# File 'lib/couch/design_document.rb', line 48

def database
  @database ||= Couch.database
end

.idObject

returns the id for design document



53
54
55
# File 'lib/couch/design_document.rb', line 53

def id
  @id ||= File.read(File.join(Couch.root, '_id.js')).strip
end

.url(options = {}) ⇒ Object

returns the url for design document



58
59
60
# File 'lib/couch/design_document.rb', line 58

def url(options = {})
  File.join(database, id) << build_options_string(options)
end

Instance Method Details

#idObject

returns the id of the design document



17
18
19
# File 'lib/couch/design_document.rb', line 17

def id
  @hash["_id"]
end

#revObject

returns the rev of the design document



22
23
24
# File 'lib/couch/design_document.rb', line 22

def rev
  @hash["_rev"]
end

#to_jsonObject

converts to json



27
28
29
# File 'lib/couch/design_document.rb', line 27

def to_json
  hash_with_injected_makros.to_json
end

#write(&block) ⇒ Object

write to filesystem



32
33
34
# File 'lib/couch/design_document.rb', line 32

def write(&block)
  write_doc @hash, nil, block
end