Class: CouchDesignDocs::Store
- Inherits:
-
Object
- Object
- CouchDesignDocs::Store
- Defined in:
- lib/couch_design_docs/store.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .delete(path) ⇒ Object
- .delete_and_put(path, doc) ⇒ Object
- .get(path) ⇒ Object
- .put(path, doc) ⇒ Object
-
.put!(path, doc) ⇒ Object
Create or replace the document located at
pathwith the Hash documentdoc.
Instance Method Summary collapse
-
#initialize(url) ⇒ Store
constructor
Initialize a CouchDB store object.
-
#load(h) ⇒ Object
Loads all supplied designed documents in the current store.
Constructor Details
#initialize(url) ⇒ Store
Initialize a CouchDB store object. Requires a URL for the target CouchDB database.
11 12 13 |
# File 'lib/couch_design_docs/store.rb', line 11 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/couch_design_docs/store.rb', line 6 def url @url end |
Class Method Details
.delete(path) ⇒ Object
45 46 47 48 49 |
# File 'lib/couch_design_docs/store.rb', line 45 def self.delete(path) # retrieve existing to obtain the revision old = self.get(path) RestClient.delete(path + "?rev=#{old['_rev']}") end |
.delete_and_put(path, doc) ⇒ Object
34 35 36 37 |
# File 'lib/couch_design_docs/store.rb', line 34 def self.delete_and_put(path, doc) self.delete(path) self.put(path, doc) end |
.get(path) ⇒ Object
51 52 53 |
# File 'lib/couch_design_docs/store.rb', line 51 def self.get(path) JSON.parse(RestClient.get(path)) end |
.put(path, doc) ⇒ Object
39 40 41 42 43 |
# File 'lib/couch_design_docs/store.rb', line 39 def self.put(path, doc) RestClient.put path, doc.to_json, :content_type => 'application/json' end |
.put!(path, doc) ⇒ Object
Create or replace the document located at path with the Hash document doc
28 29 30 31 32 |
# File 'lib/couch_design_docs/store.rb', line 28 def self.put!(path, doc) self.put(path, doc) rescue RestClient::RequestFailed self.delete_and_put(path, doc) end |
Instance Method Details
#load(h) ⇒ Object
Loads all supplied designed documents in the current store. Given a hash h, the keys being the CouchDB document name and values of design documents
19 20 21 22 23 |
# File 'lib/couch_design_docs/store.rb', line 19 def load(h) h.each_pair do |document_name, doc| Store.put!("#{url}/_design/#{document_name}", doc) end end |