Class: CouchPotato::View::ViewQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_potato/view/view_query.rb

Overview

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 Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(couchrest_database, design_document_name, view, language = :javascript) ⇒ ViewQuery

Returns a new instance of ViewQuery.



5
6
7
8
9
10
11
12
# File 'lib/couch_potato/view/view_query.rb', line 5

def initialize(couchrest_database, design_document_name, view, language = :javascript)
  @database = couchrest_database
  @design_document_name = design_document_name
  @view_name = view.keys[0]
  @map_function = view.values[0][:map]
  @reduce_function = view.values[0][:reduce]
  @language = language
end

Class Method Details

.__updated_viewsObject



30
31
32
33
# File 'lib/couch_potato/view/view_query.rb', line 30

def self.__updated_views
  @updated_views ||= {}
  @updated_views
end

.clear_cacheObject

mainly useful for testing where you drop the database between tests. only after clearing the cache design docs will be updated/re-created.



26
27
28
# File 'lib/couch_potato/view/view_query.rb', line 26

def self.clear_cache
  __updated_views.clear
end

Instance Method Details

#query_view!(parameters = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/couch_potato/view/view_query.rb', line 14

def query_view!(parameters = {})
  update_view unless view_has_been_updated?
  begin
    query_view parameters
  rescue CouchRest::NotFound
    update_view
    retry
  end
end