lib/ruote/part/storage_participant.rb in ruote-2.1.3 vs lib/ruote/part/storage_participant.rb in ruote-2.1.4

- old
+ new

@@ -55,10 +55,11 @@ doc['store_name'] = @store_name if @store_name @context.storage.put(doc) end + alias :update :consume # Makes sure to remove the workitem from the in-memory hash. # def cancel (fei, flavour) @@ -103,23 +104,45 @@ # Iterates over the workitems stored in here. # def each (&block) - fetch_all.each { |hwi| block.call(Ruote::Workitem.new(hwi)) } + all.each { |wi| block.call(wi) } end + # Returns all the workitems stored in here. + # + def all + + fetch_all.map { |hwi| Ruote::Workitem.new(hwi) } + end + # A convenience method (especially when testing), returns the first # (only ?) workitem in the participant. # def first hwi = fetch_all.first hwi ? Ruote::Workitem.new(hwi) : nil end + # Return all workitems for the specified wfid + # + def by_wfid( wfid ) + + @context.storage.get_many('workitems', /!#{wfid}$/).map { |hwi| Ruote::Workitem.new(hwi) } + end + + # Return all workitems for the specified participant + # + def by_participant( part ) + + all.select { |wi| wi.participant_name == part } + end + # Clean this participant out completely + # def purge! fetch_all.each { |hwi| @context.storage.delete( hwi ) } end