module LIBIS::Workflow::Base

Attributes

action[R]

noinspection RubyResolve

name[R]

noinspection RubyResolve

parent[R]

noinspection RubyResolve

workitem[R]

noinspection RubyResolve

Public Instance Methods

check_item_type(klass, item = nil) click to toggle source
# File lib/libis/workflow/base.rb, line 59
def check_item_type(klass, item = nil)
  item ||= workitem
  unless item.is_a? klass.to_s.constantize
    raise WorkflowError, "Workitem is of wrong type : #{item.class} - expected #{klass.to_s}"
  end
end
debug(msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 28
def debug(msg, *args)
  return if (self.options[:quiet] rescue false)
  message ::Logger::DEBUG, msg, *args
end
error(msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 43
def error(msg, *args)
  message ::Logger::ERROR, msg, *args
end
fatal(msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 47
def fatal(msg, *args)
  message ::Logger::FATAL, msg, *args
end
info(msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 33
def info(msg, *args)
  return if (self.options[:quiet] rescue false)
  message ::Logger::INFO, msg, *args
end
item_type?(klass, item = nil) click to toggle source
# File lib/libis/workflow/base.rb, line 66
def item_type?(klass, item = nil)
  item ||= workitem
  item.is_a? klass.to_s.constantize
end
message(severity, msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 51
def message (severity, msg, *args)
  log_message severity, to_msg(msg), *args
end
names() click to toggle source
# File lib/libis/workflow/base.rb, line 24
def names
  (self.parent.names rescue Array.new).push(name).compact
end
set_parent(p) click to toggle source
# File lib/libis/workflow/base.rb, line 20
def set_parent(p)
  @parent = p
end
to_status(text) click to toggle source
# File lib/libis/workflow/base.rb, line 55
def to_status(text)
  ((name || parent.name + 'Worker') + text.to_s.capitalize).to_sym
end
warn(msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 38
def warn(msg, *args)
  return if (self.options[:quiet] rescue false)
  message ::Logger::WARN, msg, *args
end

Private Instance Methods

log_message(severity, msg, *args) click to toggle source
# File lib/libis/workflow/base.rb, line 84
def log_message(severity, msg, *args)
  # Prepare info from msg struct for use with string substitution
  message_id, message_text = if msg[:id]
                               [msg[:id], MessageRegistry.instance.get_message(msg[:id])]
                             elsif msg[:text]
                               [0, msg[:text]]
                             else
                               [0, '']
                             end

  item = workitem
  item = args.shift if args.size > 0 and args[0].is_a?(WorkItem)

  # Support for named substitutions
  args = args[0] if message_text.match(/%\{\w*}/) and args.is_a? Array and args.size == 1 and args[0].is_a? Hash

  message_text = (message_text % args rescue ((message_text + ' - %s') % args.to_s))

  process_message(severity, message_id.to_i, message_text, item)

  Config.logger.add(severity, message_text, '%s - %s ' % [self.names.join('/'), (item.to_string rescue '')])
end
process_message(severity, message_id, message_text, item) click to toggle source
# File lib/libis/workflow/base.rb, line 107
def process_message(severity, message_id, message_text, item)
  return unless item and item.respond_to? :add_log
  item.add_log(
      severity: severity,
      id: message_id,
      text: message_text,
      names: self.names
  )
end
to_msg(msg) click to toggle source
# File lib/libis/workflow/base.rb, line 73
def to_msg(msg)
  case msg
    when String
      {text: msg}
    when Integer
      {id: msg}
    else
      {text: (msg.to_s rescue '')}
  end
end