Class: Ruote::Couch::WorkitemDatabase

Inherits:
WfidIndexedDatabase show all
Defined in:
lib/ruote/couch/database.rb

Overview

A Couch database with a by_wfid view and a by_field view.

Instance Attribute Summary

Attributes inherited from Database

#couch, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WfidIndexedDatabase

#by_wfid, #get_many

Methods inherited from Database

#delete, #dump, #get, #get_many, #ids, #initialize, #purge!, #put, #shutdown

Constructor Details

This class inherits a constructor from Ruote::Couch::Database

Class Method Details

.design_docObject

Returns the design document that goes with this class of database



299
300
301
302
# File 'lib/ruote/couch/database.rb', line 299

def self.design_doc

  self.allocate.send(:design_doc)
end

Instance Method Details

#by_field(field, value = nil, opts = {}) ⇒ Object

This method is called by Storage#by_field



249
250
251
252
253
254
255
# File 'lib/ruote/couch/database.rb', line 249

def by_field (field, value=nil, opts={})

  field = { field => value } if value

  @couch.query_for_docs(
    'ruote:by_field', opts.merge(:key => field))
end

#by_participant(name, opts = {}) ⇒ Object

This method is called by Storage#by_participant



259
260
261
262
263
# File 'lib/ruote/couch/database.rb', line 259

def by_participant (name, opts={})

  @couch.query_for_docs(
    'ruote:by_participant_name', opts.merge(:key => name))
end

#query_workitems(criteria) ⇒ Object

This method is called by Storage#query



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/ruote/couch/database.rb', line 267

def query_workitems (criteria)

  offset = criteria.delete('offset')
  limit = criteria.delete('limit')

  wfid =
    criteria.delete('wfid')
  pname =
    criteria.delete('participant_name') || criteria.delete('participant')

  if criteria.empty? && (wfid.nil? ^ pname.nil?)
    return by_participant(pname) if pname
    return by_wfid(wfid) # if wfid
  end

  return get_many(nil, {}) if criteria.empty?

  cr = criteria.collect { |fname, fvalue| { fname => fvalue } }

  opts = { :skip => offset, :limit => limit }

  hwis = @couch.query_for_docs('ruote:by_field', opts.merge(:keys => cr))

  hwis = hwis.select { |hwi| hwi['fei']['wfid'] == wfid } if wfid

  hwis.select { |hwi|
    Ruote::StorageParticipant.matches?(hwi, pname, criteria)
  }
end