Class: OpenWFE::IteratorExpression

Inherits:
WithTemplateExpression show all
Includes:
CommandMixin
Defined in:
lib/openwfe/expressions/fe_iterator.rb

Overview

The ‘iterator’ expression can be used like that for example :

<iterator
    on-value="alice, bob, charles"
    to-variable="user-name"
>
    <set 
        field="${user-name} comment" 
        value="(please fill this field)"
    />
</iterator>

Within the iteration, the workitem field “_ic_” contains the number of elements in the iteration and the field “_ip_” the index of the current iteration.

The ‘iterator’ expression understands the same cursor commands as the CursorExpression. One can thus exit an iterator or skip steps in it.

iterator :on_value => "alice, bob, charles, doug", to_variable => "v" do
    sequence do
        participant :variable_ref => "v"
        skip 1, :if => "${f:reply} == 'skip next'"
    end
end

For more information about those commands, see CursorCommandExpression.

Instance Attribute Summary collapse

Attributes inherited from FlowExpression

#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods inherited from WithTemplateExpression

#reply_to_parent

Methods inherited from FlowExpression

#cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Methods inherited from ObjectWithMeta

#class_def, meta_def, meta_eval, metaclass

Constructor Details

This class inherits a constructor from OpenWFE::FlowExpression

Instance Attribute Details

#iteratorObject

an Iterator instance that holds the list of values being iterated upon.



85
86
87
# File 'lib/openwfe/expressions/fe_iterator.rb', line 85

def iterator
  @iterator
end

Instance Method Details

#apply(workitem) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/openwfe/expressions/fe_iterator.rb', line 87

def apply (workitem)

    if @children.length < 1
        reply_to_parent workitem
        return
    end

    @iterator = Iterator.new(self, workitem)

    if @iterator.size < 1
        reply_to_parent workitem
        return
    end

    reply workitem
end

#reply(workitem) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/openwfe/expressions/fe_iterator.rb', line 104

def reply (workitem)

    command, step = determine_command_and_step workitem

    vars = if not command

        @iterator.next workitem

    elsif command == C_BREAK or command == C_CANCEL

        nil

    elsif command == C_REWIND or command == C_CONTINUE

        @iterator.rewind workitem

    elsif command.match "^#{C_JUMP}"

        @iterator.jump workitem, step

    else # C_SKIP or C_BACK

        @iterator.skip workitem, step
    end

    unless vars
        reply_to_parent workitem
        return
    end

    store_itself

    get_expression_pool.launch_template(
        self, nil, @iterator.index, @children[0], workitem, vars)
end