def attach(fei_or_fe, definition, opts={})
fe = Ruote.extract_fexp(@context, fei_or_fe).h
fei = fe['fei']
cfei = fei.merge(
'expid' => "#{fei['expid']}_0",
'subid' => Ruote.generate_subid(fei.inspect))
tree = @context.reader.read(definition)
tree[0] = 'sequence'
fields = fe['applied_workitem']['fields']
if fs = opts[:fields] || opts[:workitem]
fields = fs
elsif fs = opts[:merge_fields]
fields.merge!(fs)
end
@context.storage.put_msg(
'launch',
'parent_id' => fei,
'fei' => cfei,
'tree' => tree,
'workitem' => { 'fields' => fields },
'attached' => true)
Ruote::FlowExpressionId.new(cfei)
end