Class: Swarm::ProcessDefinition
Defined Under Namespace
Classes: NotYetPersistedError
Instance Attribute Summary
Attributes inherited from HiveDweller
#hive, #id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from HiveDweller
#==, all, #attributes, #change_attribute, #changed?, create, define_getter, define_setter, #delete, each, fetch, ids, inherited, #initialize, many_to_one, #new?, new_from_storage, one_to_many, reify_from_hash, #reload!, #save, #set_attributes, set_columns, #storage, #storage_id, storage_id_for_key, storage_type, #to_hash
Class Method Details
.create_from_json(json, hive: Hive.default) ⇒ Object
13
14
15
|
# File 'lib/swarm/process_definition.rb', line 13
def create_from_json(json, hive: Hive.default)
create(**parse_json_definition(json).merge(hive: hive))
end
|
.create_from_pollen(pollen, hive: Hive.default) ⇒ Object
17
18
19
20
|
# File 'lib/swarm/process_definition.rb', line 17
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) ⇒ Object
35
36
37
|
# File 'lib/swarm/process_definition.rb', line 35
def find_by_name(name)
detect { |definition| definition.name == name }
end
|
.parse_json_definition(json) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/swarm/process_definition.rb', line 22
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
|
Instance Method Details
#create_process(workitem:, **args) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/swarm/process_definition.rb', line 40
def create_process(workitem:, **args)
raise NotYetPersistedError unless id
Process.create(
**args.merge({
workitem: workitem,
process_definition_id: id
})
)
end
|
#launch_process(workitem:, **args) ⇒ Object
51
52
53
54
|
# File 'lib/swarm/process_definition.rb', line 51
def launch_process(workitem:, **args)
process = create_process(workitem: workitem, **args)
process.launch
end
|