class Libis::Workflow::ActiveRecord::WorkItem

Public Instance Methods

add_item(item) click to toggle source
Calls superclass method
# 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) click to toggle source
# 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| ... } click to toggle source
# 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_list() click to toggle source
# File lib/libis/workflow/activerecord/work_item.rb, line 80
def get_item_list
  get_items.to_a
end
get_items() click to toggle source
# File lib/libis/workflow/activerecord/work_item.rb, line 76
def get_items
  self.items.order(:id)
end
move_item(item) click to toggle source
# 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

Protected Instance Methods

add_status_log(info) click to toggle source
# File lib/libis/workflow/activerecord/work_item.rb, line 99
def add_status_log(info)
  self.status_log.build(info)
  self.status_log.last
  # noinspection RubyResolve
  # self.status_log << info.with_indifferent_access
  # self.status_log.last
end
save_log_entry(log_entry) click to toggle source
# File lib/libis/workflow/activerecord/work_item.rb, line 86
def save_log_entry(log_entry)
  log_entry.save!
  self.reload
end
status_entry(task = nil) click to toggle source
# File lib/libis/workflow/activerecord/work_item.rb, line 91
def status_entry(task = nil)
  task = task.namepath if task.is_a?(Libis::Workflow::Task)
  return self.status_log.order(id: :asc).last if task.blank?
  self.status_log.where(task: task).order(id: :asc).last
rescue Exception
  nil
end