Module: Couchbase::Operations::DesignDocs
- Defined in:
- lib/couchbase/operations/design_docs.rb
Defined Under Namespace
Classes: DesignDocAccess
Instance Method Summary collapse
-
#delete_design_doc(id, rev = nil) ⇒ true, false
Delete design doc with given id and revision.
-
#design_docs ⇒ Hash
Fetch design docs stored in current bucket.
-
#save_design_doc(data) ⇒ true, false
Update or create design doc with supplied views.
Instance Method Details
#delete_design_doc(id, rev = nil) ⇒ true, false
Delete design doc with given id and revision.
94 95 96 |
# File 'lib/couchbase/operations/design_docs.rb', line 94 def delete_design_doc(id, rev = nil) client.deleteDesignDoc(id) end |
#design_docs ⇒ Hash
Fetch design docs stored in current bucket
42 43 44 |
# File 'lib/couchbase/operations/design_docs.rb', line 42 def design_docs DesignDocAccess.new(self) end |
#save_design_doc(data) ⇒ true, false
Update or create design doc with supplied views
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/couchbase/operations/design_docs.rb', line 55 def save_design_doc(data) attrs = case data when String MultiJson.load(data) when IO MultiJson.load(data.read) when Hash data else raise ArgumentError, "Document should be Hash, String or IO instance" end id = attrs.delete('_id').to_s.split('/')[1] design_doc = DesignDocument.new(id) attrs['views'].each_pair do |view, functions| view_design = if functions['reduce'] ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string, functions['reduce'].to_java_string) else ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string) end design_doc.getViews.add(view_design) end client.createDesignDoc(design_doc) end |