Module: Ruote
- Defined in:
- lib/ruote/version.rb,
lib/ruote/fei.rb,
lib/ruote/engine.rb,
lib/ruote/reader.rb,
lib/ruote/worker.rb,
lib/ruote/context.rb,
lib/ruote/tree_dot.rb,
lib/ruote/workitem.rb,
lib/ruote/util/look.rb,
lib/ruote/util/misc.rb,
lib/ruote/util/time.rb,
lib/ruote/util/tree.rb,
lib/ruote/log/pretty.rb,
lib/ruote/reader/xml.rb,
lib/ruote/util/ometa.rb,
lib/ruote/reader/json.rb,
lib/ruote/svc/tracker.rb,
lib/ruote/util/filter.rb,
lib/ruote/util/lookup.rb,
lib/ruote/exp/fe_error.rb,
lib/ruote/storage/base.rb,
lib/ruote/util/hashdot.rb,
lib/ruote/part/template.rb,
lib/ruote/reader/radial.rb,
lib/ruote/receiver/base.rb,
lib/ruote/svc/dollar_sub.rb,
lib/ruote/log/test_logger.rb,
lib/ruote/log/wait_logger.rb,
lib/ruote/reader/ruby_dsl.rb,
lib/ruote/svc/treechecker.rb,
lib/ruote/util/serializer.rb,
lib/ruote/util/subprocess.rb,
lib/ruote/id/wfid_generator.rb,
lib/ruote/svc/dispatch_pool.rb,
lib/ruote/svc/error_handler.rb,
lib/ruote/storage/fs_storage.rb,
lib/ruote/svc/expression_map.rb,
lib/ruote/svc/expression_map.rb,
lib/ruote/log/default_history.rb,
lib/ruote/log/storage_history.rb,
lib/ruote/engine/process_error.rb,
lib/ruote/part/rev_participant.rb,
lib/ruote/storage/hash_storage.rb,
lib/ruote/svc/participant_list.rb,
lib/ruote/engine/process_status.rb,
lib/ruote/part/code_participant.rb,
lib/ruote/part/null_participant.rb,
lib/ruote/part/smtp_participant.rb,
lib/ruote/part/block_participant.rb,
lib/ruote/part/local_participant.rb,
lib/ruote/part/no_op_participant.rb,
lib/ruote/id/mnemo_wfid_generator.rb,
lib/ruote/part/engine_participant.rb,
lib/ruote/part/storage_participant.rb,
lib/ruote/storage/composite_storage.rb
Overview
– Copyright © 2005-2011, John Mettraux, [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Made in Japan. ++
Defined Under Namespace
Modules: Dollar, Exp, HashDot, JsonReader, LocalParticipant, Look, Mem, PrettyLogging, RadialReader, ReceiverMixin, RubyDsl, RubyReader, StorageBase, TemplateMixin, WithH, WithMeta, XmlReader Classes: BlankSlate, BlockParticipant, CodeParticipant, CompositeStorage, Context, DefaultHistory, DispatchPool, DollarSubstitution, Engine, EngineParticipant, EngineVariables, ErrorHandler, ExpressionMap, FlowExpressionId, ForcedError, FsStorage, HashStorage, MnemoWfidGenerator, NoOpParticipant, NullParticipant, ParticipantEntry, ParticipantList, ParticipantRegistrationProxy, ProcessError, ProcessStatus, Reader, Receiver, RevParticipant, RuleSession, Serializer, SmtpParticipant, StorageHistory, StorageParticipant, TestLogger, Tracker, TreeChecker, ValidationError, WaitLogger, WfidGenerator, Worker, Workitem
Constant Summary collapse
- VERSION =
'2.2.1'
- WIN =
Will be set to true if the Ruby runtime is on Windows
(RUBY_PLATFORM.match(/mswin|mingw/) != nil)
- JAVA =
Will be set to true if the Ruby runtime is JRuby
(RUBY_PLATFORM.match(/java/) != nil)
- REGEX_IN_STRING =
# Upon receiving something like
# # "(?-mix:nada)" # # will return # # /nada/ # def self.regex_from_s(s) if s.is_a?(String) && m = s.match(/^\(\?-mix:(.+)\)$/) Regexp.new(m[1]) else nil end end
/^\s*\/(.*)\/\s*$/
Class Method Summary collapse
-
.constantize(s) ⇒ Object
(simpler than the one from active_support).
- .decompose_tree(t, pos = '0', h = {}) ⇒ Object
-
.define(*attributes, &block) ⇒ Object
Not really a reader, more an AST builder.
-
.do_filter(filter, hash, options) ⇒ Object
Used by Ruote.filter.
-
.extract_fei(o) ⇒ Object
Given something, tries to return the fei (Ruote::FlowExpressionId) in it.
-
.extract_id(o) ⇒ Object
Will do its best to return a wfid (String) or a fei (Hash instance) extract from the given o argument.
-
.filter(filter, hash, options = {}) ⇒ Object
Given a filter (a list of rules) and a hash (probably workitem fields) performs the validations / transformations dictated by the rules.
-
.flatten_keys(o, prefix = '', accu = []) ⇒ Object
Ruote.flatten_keys({ ‘a’ => ‘b’, ‘c’ => [ 1, 2, 3 ] }) # => [ ‘a’, ‘c’, ‘c.0’, ‘c.1’, ‘c.2’ ].
-
.fulldup(object) ⇒ Object
Deep object duplication.
-
.generate_subid(salt) ⇒ Object
This function is used to generate the subids.
-
.is_a_fei?(o) ⇒ Boolean
A shortcut for.
-
.is_cron_string(s) ⇒ Object
Waiting for a better implementation of it in rufus-scheduler 2.0.4.
-
.is_definition_tree?(arg) ⇒ Boolean
Returns true if the argument is a process definition tree (whose root is ‘define’, ‘process_definition’ or ‘workflow_definition’..
-
.is_pos_tree?(arg) ⇒ Boolean
Mainly used by Ruote.lookup_subprocess, returns true if the argument is is an array [ position, tree ].
-
.is_tree?(arg) ⇒ Boolean
Returns true if the given argument is a process definition tree (its root doesn’t need to be ‘define’ or ‘process_definition’ though).
-
.is_uri?(s) ⇒ Boolean
Returns true if the string seems to correpond to a URI.
-
.keys_to_s(h) ⇒ Object
Makes sure all they keys in the given hash are turned into strings in the resulting hash.
-
.lookup(collection, key, container_lookup = false) ⇒ Object
h = { ‘a’ => { ‘b’ => [ 1, 3, 4 ] } }.
-
.lookup_subprocess(fexp, ref) ⇒ Object
This method is used by the ‘subprocess’ expression and by the EngineParticipant.
-
.narrow_to_number(o) ⇒ Object
Tries to return an Integer or a Float from the given input.
-
.neutralize(s) ⇒ Object
Returns a neutralized version of s, suitable as a filename.
-
.now_to_utc_s ⇒ Object
Returns a parsable representation of the UTC time now.
-
.or_split(filter) ⇒ Object
Used by Ruote.filter.
-
.p_caller(*msg) ⇒ Object
Prints the current call stack to stdout.
-
.process_definition(*attributes, &block) ⇒ Object
Same as Ruote.define().
- .recompose_tree(h, pos = '0') ⇒ Object
-
.regex_or_s(s) ⇒ Object
regex_or_s(“/nada/”) #==> /nada/ regex_or_s(“nada”) #==> “nada” regex_or_s(/nada/) #==> /nada/.
-
.s_to_at(s) ⇒ Object
Turns a date or a duration to a Time object pointing AT a point in time…
-
.schedule_to_h(sched) ⇒ Object
Refines a schedule as found in the ruote storage into something a bit easier to present.
-
.set(collection, key, value) ⇒ Object
h = { ‘customer’ => { ‘name’ => ‘alpha’ } }.
-
.sid(fei) ⇒ Object
A shorter shortcut for.
-
.time_to_utc_s(t) ⇒ Object
Produces the UTC string representation of a Time.
-
.to_storage_id(fei) ⇒ Object
A shortcut for.
-
.to_tree(&block) ⇒ Object
Similar in purpose to Ruote.define and Ruote.process_definition but instead of returning a [process] definition, returns the tree.
-
.tree_to_dot(tree, name = 'ruote process definition') ⇒ Object
Turns a process definition tree to a graphviz dot representation.
-
.tree_to_s(tree, expid = '0') ⇒ Object
Turning a tree into a numbered string view.
-
.unset(collection, key) ⇒ Object
h = { ‘customer’ => { ‘name’ => ‘alpha’, ‘rank’ => ‘1st’ } } r = Ruote.unset(h, ‘customer.rank’).
Class Method Details
.constantize(s) ⇒ Object
(simpler than the one from active_support)
122 123 124 125 |
# File 'lib/ruote/util/misc.rb', line 122 def self.constantize(s) s.split('::').inject(Object) { |c, n| n == '' ? c : c.const_get(n) } end |
.decompose_tree(t, pos = '0', h = {}) ⇒ Object
422 423 424 425 426 427 |
# File 'lib/ruote/engine/process_status.rb', line 422 def self.decompose_tree(t, pos='0', h={}) h[pos] = t[0, 2] t[2].each_with_index { |c, i| decompose_tree(c, "#{pos}_#{i}", h) } h end |
.define(*attributes, &block) ⇒ Object
Not really a reader, more an AST builder.
pdef = Ruote.define :name => 'take_out_garbage' do
sequence do
take_out_regular_garbage
take_out_glass
take_out_paper
end
end
engine.launch(pdef)
43 44 45 46 |
# File 'lib/ruote/reader/ruby_dsl.rb', line 43 def self.define(*attributes, &block) RubyDsl.create_branch('define', attributes, &block) end |
.do_filter(filter, hash, options) ⇒ Object
Used by Ruote.filter
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ruote/util/filter.rb', line 97 def self.do_filter(filter, hash, ) hash = Rufus::Json.dup(hash) hash['~'] = Rufus::Json.dup(hash) hash['~~'] = Rufus::Json.dup([:double_tilde] || hash) # the 'originals' deviations = filter.collect { |rule| RuleSession.new(hash, rule).run }.flatten(1) hash.delete('~') hash.delete('~~') # remove the 'originals' if deviations.empty? hash elsif [:no_raise] deviations else raise ValidationError.new(deviations) end end |
.extract_fei(o) ⇒ Object
Given something, tries to return the fei (Ruote::FlowExpressionId) in it.
74 75 76 77 |
# File 'lib/ruote/fei.rb', line 74 def self.extract_fei(o) Ruote::FlowExpressionId.extract(o) end |
.extract_id(o) ⇒ Object
Will do its best to return a wfid (String) or a fei (Hash instance) extract from the given o argument.
65 66 67 68 69 70 |
# File 'lib/ruote/fei.rb', line 65 def self.extract_id(o) return o if o.is_a?(String) and o.index('!').nil? # wfid Ruote::FlowExpressionId.extract_h(o) end |
.filter(filter, hash, options = {}) ⇒ Object
Given a filter (a list of rules) and a hash (probably workitem fields) performs the validations / transformations dictated by the rules.
See the Ruote::Exp::FilterExpression for more information.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruote/util/filter.rb', line 49 def self.filter(filter, hash, ={}) raise ArgumentError.new( "not a filter : #{filter}" ) unless filter.is_a?(Array) filters = or_split(filter) result = nil filters.each do |fl| result = begin do_filter(fl, hash, ) rescue ValidationError => err err end return result if result.is_a?(Hash) # success end raise(result) if result.is_a?(ValidationError) result end |
.flatten_keys(o, prefix = '', accu = []) ⇒ Object
Ruote.flatten_keys({ ‘a’ => ‘b’, ‘c’ => [ 1, 2, 3 ] })
# =>
[ 'a', 'c', 'c.0', 'c.1', 'c.2' ]
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/ruote/util/filter.rb', line 503 def self.flatten_keys(o, prefix='', accu=[]) if o.is_a?(Array) o.each_with_index do |elt, i| pre = "#{prefix}#{i}" accu << pre flatten_keys(elt, pre + '.', accu) end elsif o.is_a?(Hash) o.keys.sort.each do |key| pre = "#{prefix}#{key}" accu << pre flatten_keys(o[key], pre + '.', accu) end end accu end |
.fulldup(object) ⇒ Object
Deep object duplication
48 49 50 51 52 53 54 55 56 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 89 90 91 |
# File 'lib/ruote/util/misc.rb', line 48 def self.fulldup(object) return object.fulldup if object.respond_to?(:fulldup) # trusting client objects providing a fulldup() implementation # Tomaso Tosolini 2007.12.11 begin return Marshal.load(Marshal.dump(object)) # as soon as possible try to use that Marshal technique # it's quite fast rescue TypeError => te end #if object.is_a?(REXML::Element) # d = REXML::Document.new object.to_s # return d if object.kind_of?(REXML::Document) # return d.root #end # avoiding "TypeError: singleton can't be dumped" o = object.class.allocate # some kind of collection ? if object.is_a?(Array) object.each { |i| o << fulldup(i) } elsif object.is_a?(Hash) object.each { |k, v| o[fulldup(k)] = fulldup(v) } end # duplicate the attributes of the object object.instance_variables.each do |v| value = object.instance_variable_get(v) value = fulldup(value) begin o.instance_variable_set(v, value) rescue => e # ignore, must be readonly end end o end |
.generate_subid(salt) ⇒ Object
This function is used to generate the subids. Each flow expression receives such an id (it’s useful for cursors, loops and forgotten branches).
83 84 85 86 87 |
# File 'lib/ruote/fei.rb', line 83 def self.generate_subid(salt) Digest::MD5.hexdigest( "#{rand}-#{salt}-#{$$}-#{Thread.current.object_id}#{Time.now.to_f}") end |
.is_a_fei?(o) ⇒ Boolean
A shortcut for
Ruote::FlowExpressionId.is_a_fei?(o)
57 58 59 60 |
# File 'lib/ruote/fei.rb', line 57 def self.is_a_fei?(o) Ruote::FlowExpressionId.is_a_fei?(o) end |
.is_cron_string(s) ⇒ Object
Waiting for a better implementation of it in rufus-scheduler 2.0.4
90 91 92 93 94 95 96 97 98 |
# File 'lib/ruote/util/time.rb', line 90 def self.is_cron_string(s) ss = s.split(' ') return false if ss.size < 5 || ss.size > 6 return false if s.match(/\d{4}/) true end |
.is_definition_tree?(arg) ⇒ Boolean
Returns true if the argument is a process definition tree (whose root is ‘define’, ‘process_definition’ or ‘workflow_definition’.
62 63 64 65 |
# File 'lib/ruote/util/subprocess.rb', line 62 def self.is_definition_tree?(arg) Ruote::Exp::DefineExpression.is_definition?(arg) && is_tree?(arg) end |
.is_pos_tree?(arg) ⇒ Boolean
Mainly used by Ruote.lookup_subprocess, returns true if the argument is is an array [ position, tree ].
80 81 82 83 84 85 86 |
# File 'lib/ruote/util/subprocess.rb', line 80 def self.is_pos_tree?(arg) arg.is_a?(Array) && arg.size == 2 && arg[0].is_a?(String) && is_tree?(arg[1]) end |
.is_tree?(arg) ⇒ Boolean
Returns true if the given argument is a process definition tree (its root doesn’t need to be ‘define’ or ‘process_definition’ though).
70 71 72 73 74 75 |
# File 'lib/ruote/util/subprocess.rb', line 70 def self.is_tree?(arg) arg.is_a?(Array) && arg.size == 3 && arg[0].is_a?(String) && arg[1].is_a?(Hash) && arg[2].is_a?(Array) && (arg.last.empty? || arg.last.find { |e| ! is_tree?(e) }.nil?) end |
.is_uri?(s) ⇒ Boolean
Returns true if the string seems to correpond to a URI
TODO : wouldn’t it be better to simply use URI.parse() ?
97 98 99 100 |
# File 'lib/ruote/util/misc.rb', line 97 def self.is_uri?(s) s && (s.index('/') || s.match(/\.[^ ]+$/)) end |
.keys_to_s(h) ⇒ Object
Makes sure all they keys in the given hash are turned into strings in the resulting hash.
130 131 132 133 |
# File 'lib/ruote/util/misc.rb', line 130 def self.keys_to_s(h) h.inject({}) { |h, (k, v)| h[k.to_s] = v; h } end |
.lookup(collection, key, container_lookup = false) ⇒ Object
h = { ‘a’ => { ‘b’ => [ 1, 3, 4 ] } }
p Ruote.lookup(h, 'a.b.1') # => 3
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruote/util/lookup.rb', line 32 def Ruote.lookup(collection, key, container_lookup=false) return collection if key == '.' key, rest = pop_key(key) value = fetch(collection, key) return [ key, collection ] if container_lookup && rest.size == 0 return [ rest.first, value ] if container_lookup && rest.size == 1 return value if rest.size == 0 return nil if value == nil lookup(value, rest, container_lookup) end |
.lookup_subprocess(fexp, ref) ⇒ Object
This method is used by the ‘subprocess’ expression and by the EngineParticipant.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruote/util/subprocess.rb', line 35 def self.lookup_subprocess(fexp, ref) val = fexp.lookup_variable(ref) # a classical subprocess stored in a variable ? return [ '0', val ] if is_tree?(val) return val if is_pos_tree?(val) # maybe subprocess :ref => 'uri' subtree = fexp.context.reader.read(ref) rescue nil if subtree && is_definition_tree?(subtree) _, subtree = Ruote::Exp::DefineExpression.reorganize(subtree) end return [ '0', subtree ] if is_tree?(subtree) # no luck ... raise "no subprocess named '#{ref}' found" end |
.narrow_to_number(o) ⇒ Object
Tries to return an Integer or a Float from the given input. Returns
111 112 113 114 115 116 117 118 |
# File 'lib/ruote/util/misc.rb', line 111 def self.narrow_to_number(o) return o if [ Fixnum, Bignum, Float ].include?(o.class) s = o.to_s (s.index('.') ? Float(s) : Integer(s)) rescue nil end |
.neutralize(s) ⇒ Object
Returns a neutralized version of s, suitable as a filename.
104 105 106 107 |
# File 'lib/ruote/util/misc.rb', line 104 def self.neutralize(s) s.to_s.strip.gsub(/[ \/:;\*\\\+\?]/, '_') end |
.now_to_utc_s ⇒ Object
Returns a parsable representation of the UTC time now.
like “2009/11/23 11:11:50.947109 UTC”
57 58 59 60 |
# File 'lib/ruote/util/time.rb', line 57 def self.now_to_utc_s time_to_utc_s(Time.now) end |
.or_split(filter) ⇒ Object
Used by Ruote.filter
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruote/util/filter.rb', line 78 def self.or_split(filter) return filter if filter.first.is_a?(Array) return [ filter ] if filter.empty? or ( ! filter.include?('or')) # [ {}, 'or', {}, {}, 'or', {} ] filter.inject([ [] ]) do |result, fl| if fl.is_a?(Hash) result.last << fl else result << [] end result end end |
.p_caller(*msg) ⇒ Object
Prints the current call stack to stdout
38 39 40 41 42 43 44 |
# File 'lib/ruote/util/misc.rb', line 38 def self.p_caller(*msg) puts puts " == #{msg.inspect} ==" caller(1).each { |l| puts " #{l}" } puts end |
.process_definition(*attributes, &block) ⇒ Object
Same as Ruote.define()
pdef = Ruote.process_definition :name => 'take_out_garbage' do
sequence do
take_out_regular_garbage
take_out_paper
end
end
engine.launch(pdef)
59 60 61 62 |
# File 'lib/ruote/reader/ruby_dsl.rb', line 59 def self.process_definition(*attributes, &block) define(*attributes, &block) end |
.recompose_tree(h, pos = '0') ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/ruote/engine/process_status.rb', line 429 def self.recompose_tree(h, pos='0') t = h[pos] return nil unless t t << [] i = 0 loop do tt = recompose_tree(h, "#{pos}_#{i}") break unless tt t.last << tt i = i + 1 end t end |
.regex_or_s(s) ⇒ Object
regex_or_s(“/nada/”) #==> /nada/
regex_or_s("nada") #==> "nada"
regex_or_s(/nada/) #==> /nada/
158 159 160 161 162 163 164 165 |
# File 'lib/ruote/util/misc.rb', line 158 def self.regex_or_s(s) if s.is_a?(String) && m = REGEX_IN_STRING.match(s) Regexp.new(m[1]) else s end end |
.s_to_at(s) ⇒ Object
Turns a date or a duration to a Time object pointing AT a point in time…
(my prose is weak)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruote/util/time.rb', line 66 def self.s_to_at(s) at = if s.index(' ') # # date Rufus.to_ruby_time(s)# rescue nil else # # duration Time.now.utc.to_f + Rufus.parse_time_string(s) end case at when DateTime then at.to_time.utc when Float then Time.at(at).utc else at end end |
.schedule_to_h(sched) ⇒ Object
Refines a schedule as found in the ruote storage into something a bit easier to present.
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
# File 'lib/ruote/engine.rb', line 1044 def self.schedule_to_h(sched) h = sched.dup h.delete('_rev') h.delete('type') msg = h.delete('msg') owner = h.delete('owner') h['wfid'] = owner['wfid'] h['action'] = msg['action'] h['type'] = msg['flavour'] h['owner'] = Ruote::FlowExpressionId.new(owner) h['target'] = Ruote::FlowExpressionId.new(msg['fei']) h end |
.set(collection, key, value) ⇒ Object
h = { ‘customer’ => { ‘name’ => ‘alpha’ } }
Ruote.set(h, 'customer.name', 'bravo')
h #=> { 'customer' => { 'name' => 'bravo' } }
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruote/util/lookup.rb', line 53 def Ruote.set(collection, key, value) k, c = lookup(collection, key, true) if c k = k.to_i if c.is_a?(Array) c[k] = value else collection[key] = value end end |
.sid(fei) ⇒ Object
A shorter shortcut for
Ruote::FlowExpressionId.to_storage_id(fei)
48 49 50 51 |
# File 'lib/ruote/fei.rb', line 48 def self.sid(fei) Ruote::FlowExpressionId.to_storage_id(fei) end |
.time_to_utc_s(t) ⇒ Object
Produces the UTC string representation of a Time
like “2009/11/23 11:11:50.947109 UTC”
48 49 50 51 |
# File 'lib/ruote/util/time.rb', line 48 def self.time_to_utc_s(t) "#{t.utc.strftime('%Y-%m-%d %H:%M:%S')}.#{sprintf('%06d', t.usec)} UTC" end |
.to_storage_id(fei) ⇒ Object
A shortcut for
Ruote::FlowExpressionId.to_storage_id(fei)
39 40 41 42 |
# File 'lib/ruote/fei.rb', line 39 def self.to_storage_id(fei) Ruote::FlowExpressionId.to_storage_id(fei) end |
.to_tree(&block) ⇒ Object
Similar in purpose to Ruote.define and Ruote.process_definition but instead of returning a [process] definition, returns the tree.
tree = Ruote.process_definition :name => 'take_out_garbage' do
sequence do
take_out_regular_garbage
take_out_paper
end
end
p tree
# => [ 'sequence', {}, [ [ 'take_out_regular_garbage', {}, [] ], [ 'take_out_paper', {}, [] ] ] ],
This is useful when modifying a process instance via methods like re_apply :
engine.re_apply(
fei,
:tree => Ruote.to_tree {
sequence do
participant 'alfred'
participant 'bob'
end
})
#
# cancels the segment of process at fei and replaces it with
# a simple alfred-bob sequence.
91 92 93 94 |
# File 'lib/ruote/reader/ruby_dsl.rb', line 91 def self.to_tree(&block) RubyDsl.create_branch('x', {}, &block).last.first end |
.tree_to_dot(tree, name = 'ruote process definition') ⇒ Object
Turns a process definition tree to a graphviz dot representation.
32 33 34 35 36 37 |
# File 'lib/ruote/tree_dot.rb', line 32 def self.tree_to_dot(tree, name='ruote process definition') s = "digraph \"#{name}\" {\n" s << branch_to_dot('0', tree).join("\n") s << "\n}\n" end |
.tree_to_s(tree, expid = '0') ⇒ Object
Turning a tree into a numbered string view
require 'ruote/util/tree'
require 'ruote/reader/ruby_dsl'
pdef = Ruote.process_definition :name => 'def0' do
sequence do
alpha
bravo
end
end
p pdef
# => ["define", {"name"=>"def0"}, [["sequence", {}, [["alpha", {}, []], ["bravo", {}, []]]]]]
puts Ruote.tree_to_s(pdef)
# =>
# 0 define {"name"=>"def0"}
# 0_0 sequence {}
# 0_0_0 alpha {}
# 0_0_1 bravo {}
50 51 52 53 54 55 56 |
# File 'lib/ruote/util/tree.rb', line 50 def Ruote.tree_to_s(tree, expid='0') d = expid.split('_').size - 1 s = "#{' ' * d * 2}#{expid} #{tree[0]} #{tree[1].inspect}\n" tree[2].each_with_index { |t, i| s << tree_to_s(t, "#{expid}_#{i}") } s end |
.unset(collection, key) ⇒ Object
h = { ‘customer’ => { ‘name’ => ‘alpha’, ‘rank’ => ‘1st’ } }
r = Ruote.unset(h, 'customer.rank')
h # => { 'customer' => { 'name' => 'alpha' } }
r # => '1st'
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruote/util/lookup.rb', line 71 def Ruote.unset(collection, key) k, c = lookup(collection, key, true) if c.nil? collection.delete(key) elsif c.is_a?(Array) c.delete_at(Integer(k)) rescue nil elsif c.is_a?(Hash) c.delete(k) else nil end end |