ruote-maestrodev 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +290 -0
- data/CREDITS.txt +99 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +88 -0
- data/Rakefile +108 -0
- data/TODO.txt +488 -0
- data/lib/ruote.rb +7 -0
- data/lib/ruote/context.rb +194 -0
- data/lib/ruote/engine.rb +1062 -0
- data/lib/ruote/engine/process_error.rb +122 -0
- data/lib/ruote/engine/process_status.rb +448 -0
- data/lib/ruote/exp/command.rb +87 -0
- data/lib/ruote/exp/commanded.rb +69 -0
- data/lib/ruote/exp/condition.rb +227 -0
- data/lib/ruote/exp/fe_add_branches.rb +138 -0
- data/lib/ruote/exp/fe_apply.rb +154 -0
- data/lib/ruote/exp/fe_cancel_process.rb +78 -0
- data/lib/ruote/exp/fe_command.rb +156 -0
- data/lib/ruote/exp/fe_concurrence.rb +321 -0
- data/lib/ruote/exp/fe_concurrent_iterator.rb +219 -0
- data/lib/ruote/exp/fe_cron.rb +141 -0
- data/lib/ruote/exp/fe_cursor.rb +324 -0
- data/lib/ruote/exp/fe_define.rb +112 -0
- data/lib/ruote/exp/fe_echo.rb +60 -0
- data/lib/ruote/exp/fe_equals.rb +115 -0
- data/lib/ruote/exp/fe_error.rb +82 -0
- data/lib/ruote/exp/fe_filter.rb +648 -0
- data/lib/ruote/exp/fe_forget.rb +88 -0
- data/lib/ruote/exp/fe_given.rb +154 -0
- data/lib/ruote/exp/fe_if.rb +127 -0
- data/lib/ruote/exp/fe_inc.rb +205 -0
- data/lib/ruote/exp/fe_iterator.rb +234 -0
- data/lib/ruote/exp/fe_let.rb +75 -0
- data/lib/ruote/exp/fe_listen.rb +304 -0
- data/lib/ruote/exp/fe_lose.rb +110 -0
- data/lib/ruote/exp/fe_noop.rb +45 -0
- data/lib/ruote/exp/fe_once.rb +215 -0
- data/lib/ruote/exp/fe_participant.rb +287 -0
- data/lib/ruote/exp/fe_read.rb +69 -0
- data/lib/ruote/exp/fe_redo.rb +82 -0
- data/lib/ruote/exp/fe_ref.rb +152 -0
- data/lib/ruote/exp/fe_registerp.rb +110 -0
- data/lib/ruote/exp/fe_reserve.rb +126 -0
- data/lib/ruote/exp/fe_restore.rb +102 -0
- data/lib/ruote/exp/fe_save.rb +72 -0
- data/lib/ruote/exp/fe_sequence.rb +59 -0
- data/lib/ruote/exp/fe_set.rb +154 -0
- data/lib/ruote/exp/fe_subprocess.rb +211 -0
- data/lib/ruote/exp/fe_that.rb +92 -0
- data/lib/ruote/exp/fe_undo.rb +67 -0
- data/lib/ruote/exp/fe_unregisterp.rb +69 -0
- data/lib/ruote/exp/fe_wait.rb +95 -0
- data/lib/ruote/exp/flowexpression.rb +886 -0
- data/lib/ruote/exp/iterator.rb +81 -0
- data/lib/ruote/exp/merge.rb +118 -0
- data/lib/ruote/exp/ro_attributes.rb +212 -0
- data/lib/ruote/exp/ro_filters.rb +136 -0
- data/lib/ruote/exp/ro_persist.rb +154 -0
- data/lib/ruote/exp/ro_variables.rb +189 -0
- data/lib/ruote/exp/ro_vf.rb +68 -0
- data/lib/ruote/fei.rb +260 -0
- data/lib/ruote/id/mnemo_wfid_generator.rb +43 -0
- data/lib/ruote/id/wfid_generator.rb +81 -0
- data/lib/ruote/log/default_history.rb +122 -0
- data/lib/ruote/log/pretty.rb +176 -0
- data/lib/ruote/log/storage_history.rb +159 -0
- data/lib/ruote/log/test_logger.rb +208 -0
- data/lib/ruote/log/wait_logger.rb +64 -0
- data/lib/ruote/part/block_participant.rb +137 -0
- data/lib/ruote/part/code_participant.rb +81 -0
- data/lib/ruote/part/engine_participant.rb +189 -0
- data/lib/ruote/part/local_participant.rb +138 -0
- data/lib/ruote/part/no_op_participant.rb +60 -0
- data/lib/ruote/part/null_participant.rb +54 -0
- data/lib/ruote/part/rev_participant.rb +169 -0
- data/lib/ruote/part/smtp_participant.rb +116 -0
- data/lib/ruote/part/storage_participant.rb +392 -0
- data/lib/ruote/part/template.rb +84 -0
- data/lib/ruote/participant.rb +7 -0
- data/lib/ruote/reader.rb +278 -0
- data/lib/ruote/reader/json.rb +49 -0
- data/lib/ruote/reader/radial.rb +290 -0
- data/lib/ruote/reader/ruby_dsl.rb +186 -0
- data/lib/ruote/reader/xml.rb +99 -0
- data/lib/ruote/receiver/base.rb +212 -0
- data/lib/ruote/storage/base.rb +364 -0
- data/lib/ruote/storage/composite_storage.rb +121 -0
- data/lib/ruote/storage/fs_storage.rb +139 -0
- data/lib/ruote/storage/hash_storage.rb +211 -0
- data/lib/ruote/svc/dispatch_pool.rb +158 -0
- data/lib/ruote/svc/dollar_sub.rb +298 -0
- data/lib/ruote/svc/error_handler.rb +138 -0
- data/lib/ruote/svc/expression_map.rb +97 -0
- data/lib/ruote/svc/participant_list.rb +397 -0
- data/lib/ruote/svc/tracker.rb +172 -0
- data/lib/ruote/svc/treechecker.rb +141 -0
- data/lib/ruote/tree_dot.rb +85 -0
- data/lib/ruote/util/filter.rb +525 -0
- data/lib/ruote/util/hashdot.rb +79 -0
- data/lib/ruote/util/look.rb +128 -0
- data/lib/ruote/util/lookup.rb +127 -0
- data/lib/ruote/util/misc.rb +167 -0
- data/lib/ruote/util/ometa.rb +71 -0
- data/lib/ruote/util/serializer.rb +103 -0
- data/lib/ruote/util/subprocess.rb +88 -0
- data/lib/ruote/util/time.rb +100 -0
- data/lib/ruote/util/tree.rb +58 -0
- data/lib/ruote/version.rb +29 -0
- data/lib/ruote/worker.rb +386 -0
- data/lib/ruote/workitem.rb +394 -0
- data/phil.txt +14 -0
- data/ruote.gemspec +44 -0
- data/test/bm/ci.rb +55 -0
- data/test/bm/ici.rb +71 -0
- data/test/bm/juuman.rb +54 -0
- data/test/bm/launch_bench.rb +37 -0
- data/test/bm/load_26c.rb +97 -0
- data/test/bm/mega.rb +64 -0
- data/test/bm/seq_thousand.rb +31 -0
- data/test/bm/t.rb +35 -0
- data/test/functional/base.rb +247 -0
- data/test/functional/concurrent_base.rb +98 -0
- data/test/functional/crunner.rb +31 -0
- data/test/functional/ct_0_concurrence.rb +65 -0
- data/test/functional/ct_1_iterator.rb +67 -0
- data/test/functional/ct_2_cancel.rb +81 -0
- data/test/functional/eft_0_process_definition.rb +65 -0
- data/test/functional/eft_10_cancel_process.rb +46 -0
- data/test/functional/eft_11_wait.rb +109 -0
- data/test/functional/eft_12_listen.rb +500 -0
- data/test/functional/eft_13_iterator.rb +342 -0
- data/test/functional/eft_14_cursor.rb +456 -0
- data/test/functional/eft_15_loop.rb +69 -0
- data/test/functional/eft_16_if.rb +183 -0
- data/test/functional/eft_17_equals.rb +55 -0
- data/test/functional/eft_18_concurrent_iterator.rb +410 -0
- data/test/functional/eft_19_reserve.rb +136 -0
- data/test/functional/eft_1_echo.rb +68 -0
- data/test/functional/eft_20_save.rb +116 -0
- data/test/functional/eft_21_restore.rb +61 -0
- data/test/functional/eft_22_noop.rb +28 -0
- data/test/functional/eft_23_apply.rb +168 -0
- data/test/functional/eft_24_add_branches.rb +98 -0
- data/test/functional/eft_25_command.rb +28 -0
- data/test/functional/eft_26_error.rb +77 -0
- data/test/functional/eft_27_inc.rb +280 -0
- data/test/functional/eft_28_once.rb +135 -0
- data/test/functional/eft_29_cron.rb +64 -0
- data/test/functional/eft_2_sequence.rb +58 -0
- data/test/functional/eft_30_ref.rb +155 -0
- data/test/functional/eft_31_registerp.rb +130 -0
- data/test/functional/eft_32_lose.rb +93 -0
- data/test/functional/eft_33_let.rb +31 -0
- data/test/functional/eft_34_given.rb +123 -0
- data/test/functional/eft_35_filter.rb +375 -0
- data/test/functional/eft_36_read.rb +95 -0
- data/test/functional/eft_3_participant.rb +149 -0
- data/test/functional/eft_4_set.rb +296 -0
- data/test/functional/eft_5_subprocess.rb +163 -0
- data/test/functional/eft_6_concurrence.rb +304 -0
- data/test/functional/eft_7_forget.rb +61 -0
- data/test/functional/eft_8_undo.rb +114 -0
- data/test/functional/eft_9_redo.rb +138 -0
- data/test/functional/ft_0_worker.rb +65 -0
- data/test/functional/ft_10_dollar.rb +304 -0
- data/test/functional/ft_11_recursion.rb +109 -0
- data/test/functional/ft_12_launchitem.rb +43 -0
- data/test/functional/ft_13_variables.rb +151 -0
- data/test/functional/ft_14_re_apply.rb +324 -0
- data/test/functional/ft_15_timeout.rb +226 -0
- data/test/functional/ft_16_participant_params.rb +98 -0
- data/test/functional/ft_17_conditional.rb +102 -0
- data/test/functional/ft_18_kill.rb +138 -0
- data/test/functional/ft_19_participant_code.rb +67 -0
- data/test/functional/ft_1_process_status.rb +796 -0
- data/test/functional/ft_20_storage_participant.rb +543 -0
- data/test/functional/ft_21_forget.rb +153 -0
- data/test/functional/ft_22_process_definitions.rb +90 -0
- data/test/functional/ft_23_load_defs.rb +79 -0
- data/test/functional/ft_24_block_participant.rb +235 -0
- data/test/functional/ft_25_receiver.rb +207 -0
- data/test/functional/ft_26_participant_rtimeout.rb +179 -0
- data/test/functional/ft_27_var_indirection.rb +128 -0
- data/test/functional/ft_28_null_noop_participants.rb +51 -0
- data/test/functional/ft_29_part_template.rb +60 -0
- data/test/functional/ft_2_errors.rb +380 -0
- data/test/functional/ft_30_smtp_participant.rb +122 -0
- data/test/functional/ft_31_part_blocking.rb +72 -0
- data/test/functional/ft_33_participant_subprocess_priority.rb +32 -0
- data/test/functional/ft_34_cursor_rewind.rb +101 -0
- data/test/functional/ft_35_add_service.rb +56 -0
- data/test/functional/ft_36_storage_history.rb +150 -0
- data/test/functional/ft_37_default_history.rb +109 -0
- data/test/functional/ft_38_participant_more.rb +193 -0
- data/test/functional/ft_39_wait_for.rb +136 -0
- data/test/functional/ft_3_participant_registration.rb +574 -0
- data/test/functional/ft_40_wait_logger.rb +62 -0
- data/test/functional/ft_41_participants.rb +91 -0
- data/test/functional/ft_42_storage_copy.rb +71 -0
- data/test/functional/ft_43_participant_on_reply.rb +87 -0
- data/test/functional/ft_44_var_participant.rb +35 -0
- data/test/functional/ft_45_participant_accept.rb +64 -0
- data/test/functional/ft_46_launch_single.rb +83 -0
- data/test/functional/ft_47_wfid_generator.rb +54 -0
- data/test/functional/ft_48_lose.rb +112 -0
- data/test/functional/ft_49_engine_on_error.rb +201 -0
- data/test/functional/ft_4_cancel.rb +132 -0
- data/test/functional/ft_50_engine_config.rb +22 -0
- data/test/functional/ft_51_misc.rb +67 -0
- data/test/functional/ft_52_case.rb +134 -0
- data/test/functional/ft_53_engine_on_terminate.rb +95 -0
- data/test/functional/ft_54_patterns.rb +104 -0
- data/test/functional/ft_55_engine_participant.rb +303 -0
- data/test/functional/ft_56_filter_attribute.rb +259 -0
- data/test/functional/ft_57_rev_participant.rb +252 -0
- data/test/functional/ft_58_workitem.rb +69 -0
- data/test/functional/ft_59_pause.rb +343 -0
- data/test/functional/ft_5_on_error.rb +384 -0
- data/test/functional/ft_60_code_participant.rb +45 -0
- data/test/functional/ft_61_trailing_fields.rb +34 -0
- data/test/functional/ft_62_exp_name_and_dollar_substitution.rb +35 -0
- data/test/functional/ft_6_on_cancel.rb +221 -0
- data/test/functional/ft_7_tags.rb +177 -0
- data/test/functional/ft_8_participant_consumption.rb +124 -0
- data/test/functional/ft_9_subprocesses.rb +146 -0
- data/test/functional/restart_base.rb +34 -0
- data/test/functional/rt_0_wait.rb +55 -0
- data/test/functional/rt_1_listen.rb +56 -0
- data/test/functional/rt_2_errors.rb +56 -0
- data/test/functional/rt_3_once.rb +70 -0
- data/test/functional/rt_4_cron.rb +64 -0
- data/test/functional/rt_5_timeout.rb +60 -0
- data/test/functional/rtest.rb +8 -0
- data/test/functional/storage_helper.rb +93 -0
- data/test/functional/test.rb +44 -0
- data/test/functional/vertical.rb +46 -0
- data/test/path_helper.rb +15 -0
- data/test/test.rb +13 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/storage.rb +428 -0
- data/test/unit/storages.rb +37 -0
- data/test/unit/test.rb +28 -0
- data/test/unit/ut_0_ruby_reader.rb +223 -0
- data/test/unit/ut_11_lookup.rb +122 -0
- data/test/unit/ut_13_serializer.rb +65 -0
- data/test/unit/ut_14_is_uri.rb +28 -0
- data/test/unit/ut_15_util.rb +57 -0
- data/test/unit/ut_16_reader.rb +225 -0
- data/test/unit/ut_18_engine.rb +47 -0
- data/test/unit/ut_19_part_template.rb +86 -0
- data/test/unit/ut_1_fei.rb +165 -0
- data/test/unit/ut_20_composite_storage.rb +74 -0
- data/test/unit/ut_21_svc_participant_list.rb +46 -0
- data/test/unit/ut_22_filter.rb +1094 -0
- data/test/unit/ut_23_svc_tracker.rb +48 -0
- data/test/unit/ut_24_radial_reader.rb +332 -0
- data/test/unit/ut_25_merge.rb +113 -0
- data/test/unit/ut_3_wait_logger.rb +39 -0
- data/test/unit/ut_4_expmap.rb +20 -0
- data/test/unit/ut_5_tree.rb +54 -0
- data/test/unit/ut_6_condition.rb +303 -0
- data/test/unit/ut_7_workitem.rb +99 -0
- data/test/unit/ut_8_tree_to_dot.rb +72 -0
- data/test/unit/ut_9_xml_reader.rb +61 -0
- metadata +504 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
module Ruote::Exp
|
27
|
+
|
28
|
+
#
|
29
|
+
# A Mixin shared by Ruote::IteratorExpression and
|
30
|
+
# Ruote::ConcurrentIteratorExpression
|
31
|
+
#
|
32
|
+
module IteratorMixin
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def determine_list
|
37
|
+
|
38
|
+
h.times_iterator = false
|
39
|
+
|
40
|
+
#
|
41
|
+
# :times or :branches
|
42
|
+
|
43
|
+
if count = attribute(:times) || attribute(:branches)
|
44
|
+
|
45
|
+
list = ((1..count.to_i).to_a rescue nil)
|
46
|
+
|
47
|
+
if list
|
48
|
+
h.times_iterator = true
|
49
|
+
return list
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# :on{_...}
|
55
|
+
|
56
|
+
split_list(lookup_val_prefix('on'))
|
57
|
+
end
|
58
|
+
|
59
|
+
def split_list(list)
|
60
|
+
|
61
|
+
if list.is_a?(String)
|
62
|
+
|
63
|
+
sep = attribute(:separator) || attribute(:sep) || ','
|
64
|
+
list.split(sep).collect { |e| e.strip }
|
65
|
+
|
66
|
+
elsif list.respond_to?(:to_a)
|
67
|
+
|
68
|
+
list.to_a
|
69
|
+
|
70
|
+
elsif list.respond_to?(:[]) and list.respond_to?(:length)
|
71
|
+
|
72
|
+
list
|
73
|
+
|
74
|
+
else
|
75
|
+
|
76
|
+
[]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
module Ruote::Exp
|
27
|
+
|
28
|
+
#
|
29
|
+
# Gathering methods for merging workitems.
|
30
|
+
#
|
31
|
+
module MergeMixin
|
32
|
+
|
33
|
+
# Given a list of workitems and a merge_type, will merge according to
|
34
|
+
# the merge type.
|
35
|
+
#
|
36
|
+
# The return value is the merged workitem.
|
37
|
+
#
|
38
|
+
def merge_workitems(workitems, merge_type)
|
39
|
+
|
40
|
+
rworkitems = workitems.reverse
|
41
|
+
|
42
|
+
workitems.inject(nil) do |t, wi|
|
43
|
+
merge_workitem(workitems.index(wi), t, wi, merge_type)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Merge workitem 'source' into workitem 'target'.
|
48
|
+
#
|
49
|
+
# If type is 'override', the source will prevail and be returned.
|
50
|
+
#
|
51
|
+
# If type is 'mix', the source fields will be merge into the target fields.
|
52
|
+
#
|
53
|
+
# If type is 'isolate', the source fields will be placed in a separte field
|
54
|
+
# in the target workitem. The name of this field is the child_id of the
|
55
|
+
# source workitem (a string from '0' to '99999' and beyond)
|
56
|
+
#
|
57
|
+
def merge_workitem(index, target, source, merge_type)
|
58
|
+
|
59
|
+
return source if merge_type == 'override'
|
60
|
+
|
61
|
+
if target == nil
|
62
|
+
|
63
|
+
case merge_type
|
64
|
+
|
65
|
+
#when 'mix'
|
66
|
+
# do nothing
|
67
|
+
|
68
|
+
when 'stack'
|
69
|
+
source['fields'] = { 'stack' => [ source['fields'] ] }
|
70
|
+
|
71
|
+
when 'isolate'
|
72
|
+
source['fields'] = { index.to_s => source['fields'] }
|
73
|
+
|
74
|
+
#when 'union'
|
75
|
+
# do nothing
|
76
|
+
end
|
77
|
+
|
78
|
+
source
|
79
|
+
|
80
|
+
else
|
81
|
+
|
82
|
+
case merge_type
|
83
|
+
|
84
|
+
when 'mix'
|
85
|
+
|
86
|
+
target['fields'].merge!(source['fields'])
|
87
|
+
|
88
|
+
when 'stack'
|
89
|
+
|
90
|
+
target['fields']['stack'] << source['fields']
|
91
|
+
target['fields']['stack_attributes'] = expand_atts
|
92
|
+
|
93
|
+
when 'isolate'
|
94
|
+
|
95
|
+
target['fields'][index.to_s] = source['fields']
|
96
|
+
|
97
|
+
when 'union'
|
98
|
+
|
99
|
+
source['fields'].each do |k, sv|
|
100
|
+
|
101
|
+
tv = target['fields'][k]
|
102
|
+
|
103
|
+
if sv.is_a?(Array) and tv.is_a?(Array)
|
104
|
+
tv.concat(sv)
|
105
|
+
elsif sv.is_a?(Hash) and tv.is_a?(Hash)
|
106
|
+
tv.merge!(sv)
|
107
|
+
else
|
108
|
+
target['fields'][k] = sv
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
target
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
@@ -0,0 +1,212 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
module Ruote::Exp
|
27
|
+
|
28
|
+
#
|
29
|
+
# Those methods are added in FlowExpression. They were put here to offload
|
30
|
+
# FlowExpression and especially, to gather them around their attribute topic.
|
31
|
+
#
|
32
|
+
class FlowExpression
|
33
|
+
|
34
|
+
# Given a list of attribute names, returns the first attribute name for
|
35
|
+
# which there is a value.
|
36
|
+
#
|
37
|
+
def has_attribute(*args)
|
38
|
+
|
39
|
+
args.each { |a| a = a.to_s; return a if attributes[a] != nil }
|
40
|
+
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
alias :has_att :has_attribute
|
45
|
+
|
46
|
+
# Looks up the value for attribute n.
|
47
|
+
#
|
48
|
+
def attribute(n, workitem=h.applied_workitem, options={})
|
49
|
+
|
50
|
+
n = n.to_s
|
51
|
+
|
52
|
+
default = options[:default]
|
53
|
+
escape = options[:escape]
|
54
|
+
string = options[:to_s] || options[:string]
|
55
|
+
|
56
|
+
v = attributes[n]
|
57
|
+
|
58
|
+
v = if v == nil
|
59
|
+
default
|
60
|
+
elsif escape
|
61
|
+
v
|
62
|
+
else
|
63
|
+
@context.dollar_sub.s(v, self, workitem)
|
64
|
+
end
|
65
|
+
|
66
|
+
v = v.to_s if v and string
|
67
|
+
|
68
|
+
v
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the value for attribute 'key', this value should be present
|
72
|
+
# in the array list 'values'. If not, the default value is returned.
|
73
|
+
# By default, the default value is the first element of 'values'.
|
74
|
+
#
|
75
|
+
def att(key, values, opts={})
|
76
|
+
|
77
|
+
default = opts[:default] || values.first
|
78
|
+
|
79
|
+
val = attribute(key)
|
80
|
+
val = val.to_s if val
|
81
|
+
|
82
|
+
#raise(
|
83
|
+
# ArgumentError.new("attribute '#{key}' missing in #{tree}")
|
84
|
+
#) if opts[:mandatory] && val == nil
|
85
|
+
#raise(
|
86
|
+
# ArgumentError.new("attribute '#{key}' has invalid value in #{tree}")
|
87
|
+
#) if opts[:enforce] && (not values.include?(val))
|
88
|
+
|
89
|
+
values.include?(val) ? val : default
|
90
|
+
end
|
91
|
+
|
92
|
+
# prefix = 'on' => will lookup on, on_val, on_value, on_v, on_var,
|
93
|
+
# on_variable, on_f, on_fld, on_field...
|
94
|
+
#
|
95
|
+
def lookup_val_prefix(prefix, att_options={})
|
96
|
+
|
97
|
+
lval(
|
98
|
+
[ prefix ] + [ 'val', 'value' ].map { |s| "#{prefix}_#{s}" },
|
99
|
+
%w[ v var variable ].map { |s| "#{prefix}_#{s}" },
|
100
|
+
%w[ f fld field ].map { |s| "#{prefix}_#{s}" },
|
101
|
+
att_options)
|
102
|
+
end
|
103
|
+
|
104
|
+
def lookup_val(att_options={})
|
105
|
+
|
106
|
+
lval(
|
107
|
+
VV,
|
108
|
+
s_cartesian(%w[ v var variable ], VV),
|
109
|
+
s_cartesian(%w[ f fld field ], VV),
|
110
|
+
att_options)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns a Hash containing all attributes set for an expression with
|
114
|
+
# their values resolved.
|
115
|
+
#
|
116
|
+
def compile_atts(opts={})
|
117
|
+
|
118
|
+
attributes.keys.inject({}) { |r, k|
|
119
|
+
r[k] = attribute(k, h.applied_workitem, opts)
|
120
|
+
r
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
# Like compile_atts, but the keys are expanded as well.
|
125
|
+
#
|
126
|
+
# Useful for things like
|
127
|
+
#
|
128
|
+
# set "f:${v:field_name}" => "${v:that_variable}"
|
129
|
+
#
|
130
|
+
def expand_atts(opts={})
|
131
|
+
|
132
|
+
attributes.keys.inject({}) { |r, k|
|
133
|
+
kk = @context.dollar_sub.s(k, self, h.applied_workitem)
|
134
|
+
r[kk] = attribute(k, h.applied_workitem, opts)
|
135
|
+
r
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
# Given something like
|
140
|
+
#
|
141
|
+
# sequence do
|
142
|
+
# participant 'alpha'
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# in the context of the participant expression
|
146
|
+
#
|
147
|
+
# attribute_text()
|
148
|
+
#
|
149
|
+
# will yield 'alpha'.
|
150
|
+
#
|
151
|
+
# Note : an empty text returns '', not the nil value.
|
152
|
+
#
|
153
|
+
def attribute_text(workitem=h.applied_workitem)
|
154
|
+
|
155
|
+
text = attributes.keys.find { |k| attributes[k] == nil }
|
156
|
+
|
157
|
+
@context.dollar_sub.s(text.to_s, self, workitem)
|
158
|
+
end
|
159
|
+
|
160
|
+
protected
|
161
|
+
|
162
|
+
def determine_tos
|
163
|
+
|
164
|
+
to_v = attribute(:to_v) || attribute(:to_var) || attribute(:to_variable)
|
165
|
+
to_f = attribute(:to_f) || attribute(:to_fld) || attribute(:to_field)
|
166
|
+
|
167
|
+
if to = attribute(:to)
|
168
|
+
pre, key = to.split(':')
|
169
|
+
pre, key = [ 'f', pre ] if key == nil
|
170
|
+
if pre.match(/^f/)
|
171
|
+
to_f = key
|
172
|
+
else
|
173
|
+
to_v = key
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
[ to_v, to_f ]
|
178
|
+
end
|
179
|
+
|
180
|
+
# Val and Value (Sense and Sensibility ?)
|
181
|
+
#
|
182
|
+
VV = %w[ val value ]
|
183
|
+
|
184
|
+
def s_cartesian(a0, a1)
|
185
|
+
|
186
|
+
a0.inject([]) { |a, e0| a + a1.collect { |e1| "#{e0}_#{e1}" } }
|
187
|
+
end
|
188
|
+
|
189
|
+
def lval(vals, vars, flds, att_options)
|
190
|
+
|
191
|
+
if k = has_att(*vals)
|
192
|
+
|
193
|
+
attribute(k, h.applied_workitem, att_options)
|
194
|
+
|
195
|
+
elsif k = has_att(*vars)
|
196
|
+
|
197
|
+
k = attribute(k, h.applied_workitem, att_options)
|
198
|
+
lookup_variable(k)
|
199
|
+
|
200
|
+
elsif k = has_att(*flds)
|
201
|
+
|
202
|
+
k = attribute(k, h.applied_workitem, att_options)
|
203
|
+
Ruote.lookup(h.applied_workitem['fields'], k)
|
204
|
+
|
205
|
+
else
|
206
|
+
|
207
|
+
nil
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
module Ruote::Exp
|
27
|
+
|
28
|
+
#
|
29
|
+
# The methods about the :filter attribute are placed in FlowExpression
|
30
|
+
# from here.
|
31
|
+
#
|
32
|
+
class FlowExpression
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
# The :filter attribute work is done here, at apply (in) and at reply (out).
|
37
|
+
#
|
38
|
+
def filter(workitem=nil)
|
39
|
+
|
40
|
+
filter = lookup_filter(workitem)
|
41
|
+
|
42
|
+
return unless filter
|
43
|
+
|
44
|
+
unless filter.is_a?(Array)
|
45
|
+
#
|
46
|
+
# filter is a participant
|
47
|
+
|
48
|
+
def filter.receive(wi); end
|
49
|
+
# making sure the participant never replies to the engine
|
50
|
+
|
51
|
+
hwi = workitem || h.applied_workitem
|
52
|
+
|
53
|
+
if filter.respond_to?(:filter)
|
54
|
+
hwi['fields'] = filter.filter(hwi['fields'], workitem ? 'out' : 'in')
|
55
|
+
else
|
56
|
+
hwi['fields']['__filter_direction__'] = workitem ? 'out' : 'in'
|
57
|
+
filter.consume(Ruote::Workitem.new(hwi))
|
58
|
+
end
|
59
|
+
|
60
|
+
hwi['fields'].delete('__filter_direction__')
|
61
|
+
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# filter is a not a participnat
|
67
|
+
|
68
|
+
unless workitem # in
|
69
|
+
|
70
|
+
h.fields_pre_filter =
|
71
|
+
Rufus::Json.dup(h.applied_workitem['fields'])
|
72
|
+
h.applied_workitem['fields'] =
|
73
|
+
Ruote.filter(filter, h.applied_workitem['fields'], {})
|
74
|
+
|
75
|
+
else # out
|
76
|
+
|
77
|
+
workitem['fields'] =
|
78
|
+
Ruote.filter(
|
79
|
+
filter, workitem['fields'], :double_tilde => h.fields_pre_filter)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Used by #filter, deals with the various ways to pass filters
|
84
|
+
# (directly, via a variable, via a participant, in and out, ...)
|
85
|
+
#
|
86
|
+
# Returns nil, if there is no filter. Raises an ArgumentError if the
|
87
|
+
# filter is not usable. Returns the instantiated participant if the
|
88
|
+
# filter points to one.
|
89
|
+
#
|
90
|
+
def lookup_filter(workitem)
|
91
|
+
|
92
|
+
f = attribute(:filter)
|
93
|
+
|
94
|
+
return nil unless f
|
95
|
+
|
96
|
+
3.times { f = narrow_filter(f, workitem) }
|
97
|
+
|
98
|
+
raise ArgumentError.new(
|
99
|
+
"found no filter corresponding to '#{f}'"
|
100
|
+
) unless f
|
101
|
+
|
102
|
+
f
|
103
|
+
end
|
104
|
+
|
105
|
+
# Called successively to dig for the filter (Array or Participant).
|
106
|
+
#
|
107
|
+
def narrow_filter(fi, workitem)
|
108
|
+
|
109
|
+
if fi.is_a?(Array) or fi.respond_to?(:consume) or fi.respond_to?(:filter)
|
110
|
+
|
111
|
+
fi
|
112
|
+
|
113
|
+
elsif fi.is_a?(Hash)
|
114
|
+
|
115
|
+
workitem ? fi['out'] || fi['reply'] : fi['in'] || fi['apply']
|
116
|
+
|
117
|
+
elsif fi.is_a?(String)
|
118
|
+
|
119
|
+
filter =
|
120
|
+
lookup_variable(fi) ||
|
121
|
+
@context.plist.lookup(fi, workitem || h.applied_workitem)
|
122
|
+
|
123
|
+
if filter.respond_to?(:consume) or filter.respond_to?(:filter)
|
124
|
+
(workitem || h.applied_workitem)['participant_name'] = fi
|
125
|
+
end
|
126
|
+
|
127
|
+
filter
|
128
|
+
|
129
|
+
else
|
130
|
+
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|