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, #delete, each, fetch, ids, inherited, #initialize, many_to_one, #new?, new_from_storage, one_to_many, #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
11
12
13
|
# 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) ⇒ Object
15
16
17
18
|
# 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) ⇒ Object
33
34
35
|
# File 'lib/swarm/process_definition.rb', line 33
def find_by_name(name)
detect { |definition| definition.name == name }
end
|
.parse_json_definition(json) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# 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
|
Instance Method Details
#create_process(workitem:, **args) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# 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) ⇒ Object
48
49
50
51
|
# File 'lib/swarm/process_definition.rb', line 48
def launch_process(workitem:, **args)
process = create_process(workitem: workitem, **args)
process.launch
end
|