Sha256: 4a35dbf6fd31a0a13cc448fc00b3e22809b1d498b0ec38d87e77d42f4849854c
Contents?: true
Size: 1.65 KB
Versions: 15
Compression:
Stored size: 1.65 KB
Contents
require 'digest/md5' module CouchRest module Mixins module DesignDoc def self.included(base) base.extend(ClassMethods) end module ClassMethods def design_doc_id "_design/#{design_doc_slug}" end def design_doc_slug return design_doc_slug_cache if (design_doc_slug_cache && design_doc_fresh) funcs = [] design_doc ||= Design.new(default_design_doc) design_doc['views'].each do |name, view| funcs << "#{name}/#{view['map']}#{view['reduce']}" end md5 = Digest::MD5.hexdigest(funcs.sort.join('')) self.design_doc_slug_cache = "#{self.to_s}-#{md5}" end def default_design_doc { "language" => "javascript", "views" => { 'all' => { 'map' => "function(doc) { if (doc['couchrest-type'] == '#{self.to_s}') { emit(null,null); } }" } } } end def refresh_design_doc did = design_doc_id saved = database.get(did) rescue nil if saved design_doc['views'].each do |name, view| saved['views'][name] = view end database.save_doc(saved) self.design_doc = saved else design_doc['_id'] = did design_doc.delete('_rev') design_doc.database = database design_doc.save end self.design_doc_fresh = true end end # module ClassMethods end end end
Version data entries
15 entries across 15 versions & 6 rubygems