class Swarm::ProcessDefinition

Public Class Methods

create_from_json(json, hive: Hive.default) click to toggle source
# File lib/swarm/process_definition.rb, line 11
def create_from_json(json, hive: Hive.default)
  create(**parse_json_definition(json).merge(:hive => hive))
end
create_from_pollen(pollen, hive: Hive.default) click to toggle source
# File lib/swarm/process_definition.rb, line 15
def create_from_pollen(pollen, hive: Hive.default)
  json = Swarm::Pollen::Reader.new(pollen).to_json
  create_from_json(json, hive: hive)
end
find_by_name(name) click to toggle source
# File lib/swarm/process_definition.rb, line 33
def find_by_name(name)
  detect { |definition| definition.name == name }
end
parse_json_definition(json) click to toggle source
# File lib/swarm/process_definition.rb, line 20
def parse_json_definition(json)
  parsed = JSON.parse(json)
  if parsed.is_a?(Array)
    { :tree => parsed }
  else
    {
      :name => parsed["name"],
      :version => parsed["version"],
      :tree => parsed["definition"]
    }
  end
end

Public Instance Methods

create_process(workitem:, **args) click to toggle source
# File lib/swarm/process_definition.rb, line 38
def create_process(workitem:, **args)
  raise NotYetPersistedError unless id
  Process.create(
    args.merge({
      :workitem => workitem,
      :process_definition_id => id
    })
  )
end
launch_process(workitem:, **args) click to toggle source
# File lib/swarm/process_definition.rb, line 48
def launch_process(workitem:, **args)
  process = create_process(workitem: workitem, **args)
  process.launch
end