module Couchbase::Operations::DesignDocs
Public Instance Methods
delete_design_doc(id, rev = nil)
click to toggle source
Delete
design doc with given id and revision.
@since 1.2.0
@param [String] id Design document id. It might have '_design/'
prefix.
@param [String] rev Document revision. It uses latest revision if
+rev+ parameter is nil.
@return [true, false]
# File lib/couchbase/operations/design_docs.rb, line 94 def delete_design_doc(id, rev = nil) client.deleteDesignDoc(id) end
design_docs()
click to toggle source
Fetch design docs stored in current bucket
@since 1.2.0
@return [Hash]
# File lib/couchbase/operations/design_docs.rb, line 42 def design_docs DesignDocAccess.new(self) end
save_design_doc(data)
click to toggle source
Update or create design doc with supplied views
@since 1.2.0
@param [Hash, IO, String] data The source object containing JSON
encoded design document. It must have +_id+ key set, this key should start with +_design/+.
@return [true, false]
# 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