Class: Ruote::Exp::RestoreExpression

Inherits:
FlowExpression show all
Includes:
MergeMixin
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 included from MergeMixin

#merge_workitem, #merge_workitems

Methods inherited from FlowExpression

#ancestor?, #att, #attribute, #attribute_text, #attributes, #cancel, #compile_atts, #compile_variables, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_resume, #do_unpersist, #expand_atts, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #iterative_var_lookup, #launch_sub, #lookup_on_error, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #persist_or_raise, #reply_to_parent, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables

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



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
89
90
91
92
93
94
# File 'lib/ruote/exp/fe_restore.rb', line 63

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



96
97
98
99
# File 'lib/ruote/exp/fe_restore.rb', line 96

def reply(workitem)

  # empty, never called
end