Class: Ruote::Exp::RestoreExpression

Inherits:
FlowExpression show all
Defined in:
lib/ruote/exp/fe_restore.rb

Overview

Restores the fields of the current workitem. That means usually copying them from a saved version in a variable or in a separate field.

restore :from_var => 'v'

or

restore :from_f => 'customer.address.street', :to_f => 'delivery.street'

(yes, this sets the field ‘street’ inside of the field ‘delivery’)

set_fields

This expressions has a ‘set_fields’ alias. It can be handy (and readable) to set a bunch of workitem fields in one sweep somewhere in a process :

Ruote.process_definition :name => 'working hard' do
  sequence do
    set_fields :val => { 'customer' => { 'name' => 'Fred', 'age' => 40 } }
    participant :ref => 'delivery'
    participant :ref => 'invoincing'
  end
end

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error, #h

Instance Method Summary collapse

Methods inherited from FlowExpression

#ancestor?, #applied_workitem, #att, #att_text, #attribute, #attribute_text, #attributes, #await, #cancel, #cancel_flanks, #cfei_at, #child_id, #child_ids, #compile_atts, #compile_variables, #debug_id, #deflate, #do, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_reply_to_parent, #do_resume, #do_unpersist, dummy, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #is_concurrent?, #iterative_var_lookup, #launch_sub, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #pause_on_apply, #persist_or_raise, #reply_to_parent, #root, #root_id, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables, #wfid

Methods included from WithMeta

#class_def, included

Methods included from WithH

included

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#applyObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ruote/exp/fe_restore.rb', line 57

def apply

  from =
    has_attribute(*%w[ v var variable ].map { |k| "from_#{k}" }) ||
    has_attribute(*%w[ f fld field ].map { |k| "from_#{k}" }) ||
    has_attribute(*%w[ val value ])

  _, to_f = determine_tos
    # note : to_v is discarded (the underscore)

  from = 'from_var' if from == 'from_v'

  afrom = attribute(from)

  fields = if from.match(/var/)
    lookup_variable(afrom)
  elsif from.match(/f/)
    Ruote.lookup(h.applied_workitem['fields'], afrom)
  else # val
    afrom
  end

  if to_f
    Ruote.set(h.applied_workitem['fields'], to_f, fields)
  else
    h.applied_workitem['fields'] = fields
  end

  # TODO : merge strategies

  reply_to_parent(h.applied_workitem)
end

#reply(workitem) ⇒ Object



90
91
92
93
# File 'lib/ruote/exp/fe_restore.rb', line 90

def reply(workitem)

  # empty, never called
end