Sha256: c4af4796f1a3984d62f9b45e0d3a6e74527cdeab5c5a2fb9b2e2a393d2a428a2
Contents?: true
Size: 1.33 KB
Versions: 4
Compression:
Stored size: 1.33 KB
Contents
module CouchPotato module View # Used to query views (and create them if they don't exist). Usually you won't have to use this class directly. Instead it is used internally by the CouchPotato::Database.view method. class ViewQuery def initialize(couchrest_database, design_document_name, view_name, map_function, reduce_function = nil) @database = couchrest_database @design_document_name = design_document_name @view_name = view_name @map_function = map_function @reduce_function = reduce_function end def query_view!(parameters = {}) begin query_view parameters rescue RestClient::ResourceNotFound => e create_view retry end end private def create_view design_doc = @database.get "_design/#{@design_document_name}" rescue nil design_doc ||= {'views' => {}, "_id" => "_design/#{@design_document_name}"} design_doc['views'][@view_name.to_s] = { 'map' => @map_function, 'reduce' => @reduce_function } @database.save_doc(design_doc) end def query_view(parameters) @database.view view_url, parameters end def view_url "#{@design_document_name}/#{@view_name}" end end end end
Version data entries
4 entries across 4 versions & 1 rubygems