Class: Couch::DesignDocument
- Inherits:
-
Object
- Object
- Couch::DesignDocument
- 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
-
.build_from_filesystem(root) ⇒ Object
returns new design document object from filesystem.
-
.build_from_json(json) ⇒ Object
returns new design document object from json string.
-
.database ⇒ Object
returns the database used to store design document.
-
.id ⇒ Object
returns the id for design document.
-
.url(options = {}) ⇒ Object
returns the url for design document.
Instance Method Summary collapse
-
#id ⇒ Object
returns the id of the design document.
-
#initialize(hash = {}) ⇒ DesignDocument
constructor
initialize with a hash.
-
#rev ⇒ Object
returns the rev of the design document.
-
#to_json ⇒ Object
converts to json.
-
#write(&block) ⇒ Object
write to filesystem.
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 |
.database ⇒ Object
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 |
.id ⇒ Object
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( = {}) File.join(database, id) << () end |
Instance Method Details
#id ⇒ Object
returns the id of the design document
17 18 19 |
# File 'lib/couch/design_document.rb', line 17 def id @hash["_id"] end |
#rev ⇒ Object
returns the rev of the design document
22 23 24 |
# File 'lib/couch/design_document.rb', line 22 def rev @hash["_rev"] end |
#to_json ⇒ Object
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 |