lib/ruote/dm/storage.rb in ruote-dm-2.1.6 vs lib/ruote/dm/storage.rb in ruote-dm-2.1.7
- old
+ new
@@ -39,10 +39,13 @@
property :doc, Text, :length => 2**32 - 1, :required => true, :lazy => false
property :participant_name, String, :length => 512
end
+ #
+ # A datamapper-powered storage for ruote.
+ #
class DmStorage
include Ruote::StorageBase
attr_reader :repository
@@ -124,18 +127,17 @@
if l = opts[:limit]
q[:limit] = l
end
if key
- key = if m = key.source.match(/(.+)\$$/)
+ q[:ide.like] = if m = key.source.match(/(.+)\$$/)
"%#{m[1]}"
elsif m = key.source.match(/^\^(.+)/)
"#{m[1]}%"
else
- key
+ "%#{key.source}%"
end
- q[:ide.like] = key
end
DataMapper.repository(@repository) do
Document.all(q).collect { |d| Rufus::Json.decode(d.doc) }
end
@@ -204,9 +206,35 @@
like.push(Rufus::Json.encode(value)) if value
like.push('%')
Document.all(:typ => type, :doc.like => like.join).collect { |d|
Rufus::Json.decode(d.doc)
+ }
+ end
+
+ def query_workitems (criteria)
+
+ offset = criteria.delete('offset')
+ limit = criteria.delete('limit')
+
+ wfid =
+ criteria.delete('wfid')
+ pname =
+ criteria.delete('participant_name') || criteria.delete('participant')
+
+ cr = { :typ => 'workitems' }
+
+ cr[:ide.like] = "%!#{wfid}" if wfid
+ cr[:offset] = offset if offset
+ cr[:limit] = limit if limit
+ cr[:participant_name] = pname if pname
+
+ criteria.each do |k, v|
+ cr[:doc.like] = "%\"#{k}\":#{Rufus::Json.encode(v)}%"
+ end
+
+ Document.all(cr).collect { |d|
+ Ruote::Workitem.new(Rufus::Json.decode(d.doc))
}
end
protected