WIN | = | (RUBY_PLATFORM.match(/mswin|mingw/) != nil) | Will be set to true if the Ruby runtime is on Windows | |
JAVA | = | (RUBY_PLATFORM.match(/java/) != nil) | Will be set to true if the Ruby runtime is JRuby | |
REGEX_IN_STRING | = | /^\s*\/(.*)\/\s*$/ | ||
SUBS | = | %w[ subid sub_wfid ] | ||
IDS | = | %w[ engine_id expid wfid ] | ||
DUMMY_WORKER | = | OpenStruct.new( :name => 'worker', :identity => 'unknown', :state => 'running') | A helper for the worker method, it returns that dummy worker when there is no reference to the calling worker in the current thread‘s local variables. | |
VERSION | = | '2.3.0.3' |
deep_delete | -> | delete_all |
to_tree | -> | tree |
Our own quick camelize implementation (no need to require active support).
Returns an array. If the argument is an array, return it as is. Else turns the argument into a string and "comma splits" it.
Compacts
[ 'participant', { 'ref' => 'sam' }, [] ] # and [ 'subprocess', { 'ref' => 'compute_prime' }, [] ]
into
[ 'sam', {}, [] ] # and [ 'compute_prime', {}, [] ]
to simplify tree comparisons.
Warning, this is not equivalent to doing @context.worker, this method fetches the worker from the local thread variables.
Used by some projects, used to be called from Ruote::ProcessStatus.
Given a tree
[ 'define', { 'name' => 'nada' }, [ [ 'sequence', {}, [ [ 'alpha', {}, [] ], [ 'bravo', {}, [] ] ] ] ] ]
will output something like
{ '0' => [ 'define', { 'name' => 'nada' } ], '0_0' => [ 'sequence', {} ], '0_0_0' => [ 'alpha', {} ], '0_0_1' => [ 'bravo', {} ] },
An initial offset can be specifid with the ‘pos’ argument.
Don‘t touch ‘h’, it‘s an accumulator.
Given a hash and a key, deletes all the entries with that key, in child hashes too.
Note: this method is not related to the "dot notation" methods in this lookup.rb file.
h = { 'a' => 1, 'b' => { 'a' => 2 } } Ruote.deep_delete(h, 'a') # => { 'b' => {} }
Dives into a nested structure of hashes and arrays to find match hash keys.
The method expects a block with 3 or 4 arguments.
3 arguments: collection, key and value 4 arguments: parent collection, collection, key and value
Warning: .deep_mutate forces hash keys to be strings. It‘s a JSON world.
h = { 'a' => 0, 'b' => 1, 'c' => { 'a' => 2, 'b' => { 'a' => 3 } }, 'd' => [ { 'a' => 0 }, { 'b' => 4 } ] } Ruote.deep_mutate(h, 'a') do |coll, k, v| coll['a'] = 10 end h # => { 'a' => 10, 'b' => 1, 'c' => { 'a' => 10, 'b' => { 'a' => 10 } }, 'd' => [ { 'a' => 10 }, { 'b' => 4 } ] }
Instead of a single key, it‘s OK to pass an array of keys:
Ruote.deep_mutate(a, [ 'a', 'b' ]) do |coll, k, v| # ... end
Regular expressions are made to match:
Ruote.deep_mutate(a, [ 'a', /^a\./ ]) do |coll, k, v| # ... end
A single regular expression is OK:
Ruote.deep_mutate(a, /^user\./) do |coll, k, v| # ... end
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)
Given something that might be a fei, extract the child_id (the last portion of the expid in the fei).
Given a context and a fei (FlowExpressionId or Hash) or a flow expression (Ruote::Exp::FlowExpression or Hash) return the desired Ruote::Exp::FlowExpression instance.
Will do its best to return a wfid (String) or a fei (Hash instance) extract from the given o argument.
Given an object, will return the wfid (workflow instance id) nested into it (or nil if it can‘t find or doesn‘t know how to find).
The wfid is a String instance.
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.
This function is used to generate the subids. Each flow expression receives such an id (it‘s useful for cursors, loops and forgotten branches).
h = { ‘a’ => { ‘b’ => [ 1, 3, 4 ] } }
p Ruote.lookup(h, ‘a.b.1’) # => true
Returns true if the argument is a process definition tree (whose root is ‘define’, ‘process_definition’ or ‘workflow_definition’.
Mainly used by Ruote.lookup_subprocess, returns true if the argument is is an array [ position, tree ].
Returns true if the given argument is a process definition tree (its root doesn‘t need to be ‘define’ or ‘process_definition’ though).
Returns true if the string seems to correpond to a URI
TODO : wouldn‘t it be better to simply use URI.parse() ?
Makes sure all they keys in the given hash are turned into symbols in the resulting hash.
Mostly used in ruote-amqp.
From coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
Returns the (one of the) local IP address.
h = { ‘a’ => { ‘b’ => [ 1, 3, 4 ] } }
p Ruote.lookup(h, ‘a.b.1’) # => 3
This method is used by the ‘subprocess’ expression and by the EngineParticipant.
Merge workitem ‘source’ into workitem ‘target’.
If type is ‘override’, the source will prevail and be returned.
If type is ‘mix’, the source fields will be merged into the target fields.
If type is ‘isolate’, the source fields will be placed in a separte field in the target workitem. The name of this field is the child_id of the source workitem (a string from ‘0’ to ‘99999’ and beyond)
The ‘concat’ type merges hashes and concats arrays. The ‘union’ type behaves much like ‘concat’, but it makes sure to remove duplicates.
Warning: ‘union’ will remove duplicates that were present before the merge.
Given a participant, a method name or an array of method names and a hash of arguments, will do its best to set the instance variables corresponding to the arguments (if possible) and to call the method with the right number of arguments…
Made it a Ruote module method so that RevParticipant might use it independently.
If the arguments hash contains a value keyed :default, that value is returned when none of the methods is responded to by the participant. Else if :default is not set or is set to nil, a NoMethodError.
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)
Used by some projects, used to be called from Ruote::ProcessStatus.
Given a decomposed tree like
{ '0' => [ 'define', { 'name' => 'nada' } ], '0_0' => [ 'sequence', {} ], '0_0_0' => [ 'alpha', {} ], '0_0_1' => [ 'bravo', {} ] },
will recompose it to
[ 'define', { 'name' => 'nada' }, [ [ 'sequence', {}, [ [ 'alpha', {}, [] ], [ 'bravo', {}, [] ] ] ] ] ]
A starting point in the recomposition can be given with the ‘pos’ argument.
regex_or_s("/nada/") #==> /nada/ regex_or_s("nada") #==> "nada" regex_or_s(/nada/) #==> /nada/
h = { ‘customer’ => { ‘name’ => ‘alpha’ } }
Ruote.set(h, ‘customer.name’, ‘bravo’)
h #=> { ‘customer’ => { ‘name’ => ‘bravo’ } }
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.
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 {}
h = { ‘customer’ => { ‘name’ => ‘alpha’, ‘rank’ => ‘1st’ } } r = Ruote.unset(h, ‘customer.rank’)
h # => { ‘customer’ => { ‘name’ => ‘alpha’ } } r # => ‘1st‘
Given a collection and a key returns the corresponding value
Ruote.fetch([ 12, 13, 24 ], 1) # => 13 Ruote.fetch({ '1' => 13 }, 1) # => 13 Ruote.fetch({ 1 => 13 }, 1) # => 13