Class: Libis::Workflow::Mongoid::WorkItem

Inherits:
Object
  • Object
show all
Includes:
Base::WorkItem, Base
Defined in:
lib/libis/workflow/mongoid/work_item.rb

Direct Known Subclasses

Run

Instance Method Summary collapse

Methods included from Base

included, #to_hash, #to_s

Instance Method Details

#add_item(item) ⇒ Object

Raises:

  • (Libis::WorkflowError)


29
30
31
32
# File 'lib/libis/workflow/mongoid/work_item.rb', line 29

def add_item(item)
  raise Libis::WorkflowError, 'Trying to add item already linked to another item' unless item.parent.nil?
  super(item)
end

#copy_item(item) {|new_item, item| ... } ⇒ Object

Yields:

  • (new_item, item)


34
35
36
37
38
39
40
41
# File 'lib/libis/workflow/mongoid/work_item.rb', line 34

def copy_item(item)
  new_item = item.dup
  yield new_item, item if block_given?
  new_item.parent = nil
  item.get_items.each { |i| new_item.copy_item(i) }
  self.add_item(new_item)
  new_item
end

#get_item_listObject



59
60
61
# File 'lib/libis/workflow/mongoid/work_item.rb', line 59

def get_item_list
  self.items.to_a
end

#get_itemsObject



55
56
57
# File 'lib/libis/workflow/mongoid/work_item.rb', line 55

def get_items
  self.items.no_timeout
end

#move_item(item) {|new_item, item| ... } ⇒ Object

Yields:

  • (new_item, item)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/libis/workflow/mongoid/work_item.rb', line 43

def move_item(item)
  new_item = item.dup
  yield new_item, item if block_given?
  new_item.parent = nil
  item.get_items.each { |i| new_item.move_item(i) }
  self.add_item(new_item)
  if item.parent
    item.parent.items.delete(item)
  end
  new_item
end