Class: Libis::Workflow::ActiveRecord::WorkItem

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Base, Helpers::PropertyHelper, Base::WorkItem
Defined in:
lib/libis/workflow/activerecord/work_item.rb

Direct Known Subclasses

Run

Instance Method Summary collapse

Methods included from Helpers::PropertyHelper

included

Methods included from Base

included, #to_hash, #to_s

Instance Method Details

#add_item(item) ⇒ Object

Raises:

  • (Libis::WorkflowError)


44
45
46
47
# File 'lib/libis/workflow/activerecord/work_item.rb', line 44

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, &block) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/libis/workflow/activerecord/work_item.rb', line 59

def copy_item(item, &block)
  new_item = item.duplicate &block
  new_item.parent = nil
  add_item new_item
  item.items.each {|i| new_item.copy_item(i)}
  new_item
end

#duplicate {|new_item| ... } ⇒ Object

Yields:

  • (new_item)


49
50
51
52
53
54
55
56
57
# File 'lib/libis/workflow/activerecord/work_item.rb', line 49

def duplicate
  new_item = self.class.new
  new_item.properties = {}.with_indifferent_access
  self.properties.each {|k, v| new_item.properties[k.to_sym] = v.dup}
  new_item.options = {}.with_indifferent_access
  self.options.each {|k, v| new_item.options[k.to_sym] = v.dup}
  yield new_item if block_given?
  new_item
end

#get_item_listObject



80
81
82
# File 'lib/libis/workflow/activerecord/work_item.rb', line 80

def get_item_list
  get_items.to_a
end

#get_itemsObject



76
77
78
# File 'lib/libis/workflow/activerecord/work_item.rb', line 76

def get_items
  self.items.order(:id)
end

#move_item(item) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/libis/workflow/activerecord/work_item.rb', line 67

def move_item(item)
  old_parent = item.parent
  item.parent = self
  item.save
  old_parent.items.reset
  self.items.reset
  item
end