lib/openwfe/expressions/flowexpression.rb in openwferu-0.9.15 vs lib/openwfe/expressions/flowexpression.rb in openwferu-0.9.16

- old
+ new

@@ -142,11 +142,11 @@ # this default implementation immediately replies to the # parent expression # def apply (workitem) - get_parent().reply(workitem) if @parent_id + get_parent.reply(workitem) if @parent_id end # # this default implementation immediately replies to the # parent expression @@ -178,11 +178,11 @@ inflowitem = nil @children.each do |child| - next if child.kind_of? String + next if child.kind_of?(String) i = get_expression_pool().cancel(child) inflowitem = i unless inflowitem end @@ -195,10 +195,11 @@ # # Returns the parent expression (not as a FlowExpressionId but directly # as the FlowExpression instance it is). # def get_parent + #parent, parent_fei = get_expression_pool.fetch @parent_id #parent get_expression_pool.fetch_expression @parent_id end @@ -208,11 +209,12 @@ # themselves as soon as their state changed. # Else this information would be lost at engine restart or # simply if the expression got swapped out of memory and reloaded later. # def store_itself - #ldebug { "store_itself() for #{@fei.to_debug_s}" } + + ldebug { "store_itself() for #{@fei.to_debug_s}" } #ldebug { "store_itself() \n#{OpenWFE::caller_to_s(0, 6)}" } get_expression_pool.update self end # @@ -305,14 +307,14 @@ # def set_variable (varname, value) env, var = lookup_environment(varname) - #ldebug do - # "set_variable() '#{varname}' to '#{value}' " + - # "in #{env.fei.to_debug_s}" - #end + ldebug do + "set_variable() '#{varname}' to '#{value}' " + + "in #{env.fei.to_debug_s}" + end env[var] = value end # @@ -358,61 +360,89 @@ # # The various methods for looking up attributes do perform dollar # variable substitution. # It's ok to pass a Symbol for the attribute name. # - def lookup_attribute (attname, workitem, default=nil) + def lookup_attribute (attname, workitem, options={}) + default = options[:default] + escape = options[:escape] + attname = OpenWFE::symbol_to_name(attname) \ - if attname.kind_of? Symbol + if attname.kind_of?(Symbol) #ldebug { "lookup_attribute() '#{attname}' in #{@fei.to_debug_s}" } text = @attributes[attname] - default = default.to_s if default + return default if text == nil + return text unless text.is_a?(String) - return default if not text + return text if escape == true + # returns text if escape is set and is set to true - OpenWFE::dosub(text, self, workitem) + OpenWFE::dosub text, self, workitem end # - # Like lookup_attribute() but returns the value downcased. - # Returns nil if no such attribute was found. + # Returns the attribute value as a String (or nil if it's not found). # - def lookup_downcase_attribute (attname, workitem, default=nil) - result = lookup_attribute attname, workitem, default - result = result.downcase if result + def lookup_string_attribute (attname, workitem, options={}) + + result = lookup_attribute attname, workitem, options + result = result.to_s if result result end # - # Returns true if the expression has the given attribute. - # The attname parameter can be a String or a Symbol. + # Like lookup_attribute() but returns the value downcased [ + # (and stripped). + # Returns nil if no such attribute was found. # - def has_attribute (attname) + def lookup_downcase_attribute (attname, workitem, options={}) - attname = OpenWFE::symbol_to_name(attname) \ - if attname.kind_of? Symbol + result = lookup_string_attribute attname, workitem, options + result = result.strip.downcase if result + result + end - @attributes[attname] != nil + # + # Returns the value of the attribute as a Symbol. + # Returns nil if there is no attribute under the given name. + # + def lookup_sym_attribute (attname, workitem, options={}) + + result = lookup_downcase_attribute attname, workitem, options + result = result.to_sym if result + result end # # A convenience method for looking up a boolean value. # It's ok to pass a Symbol for the attribute name. # def lookup_boolean_attribute (attname, workitem, default=false) - value = lookup_attribute(attname, workitem) - return default if not value + result = lookup_downcase_attribute attname, workitem + return default if result == nil - (value.downcase == 'true') + (result == 'true') end # + # Returns true if the expression has the given attribute. + # The attname parameter can be a String or a Symbol. + # + def has_attribute (attname) + + attname = OpenWFE::symbol_to_name(attname) \ + if attname.kind_of?(Symbol) + + @attributes[attname] != nil + end + + # # Returns a hash of all the FlowExpression attributes with their # values having undergone dollar variable substitution. # If the attributes parameter is set (to an Array instance) then # only the attributes named in that list will be looked up. # @@ -452,13 +482,13 @@ # # will return # # [ 'a', 'b', 'c' ] # - def lookup_comma_list_attribute (attname, workitem, default=nil) + def lookup_comma_list_attribute (attname, workitem, options={}) - a = lookup_attribute(attname, workitem, default) + a = lookup_attribute(attname, workitem, options) return nil if not a result = [] a.split(',').each do |elt| @@ -593,42 +623,48 @@ # # looks up for 'value', 'variable-value' and then for 'field-value' # if necessary. # - def lookup_value (workitem, prefix='') + def lookup_value (workitem, options={}) - v = lookup_vf_attribute(workitem, 'value', prefix) - v = lookup_vf_attribute(workitem, 'val', prefix) unless v + v = lookup_vf_attribute(workitem, 'value', options) + v = lookup_vf_attribute(workitem, 'val', options) unless v v end # # looks up for 'ref', 'variable-ref' and then for 'field-ref' # if necessary. # def lookup_ref (workitem, prefix='') - lookup_vf_attribute(workitem, 'ref', prefix) + ref = lookup_vf_attribute(workitem, 'ref', :prefix => prefix) + return ref.to_s if ref + nil end # # Looks up for value attributes like 'field-ref' or 'variable-value' # - def lookup_vf_attribute (workitem, att_name, prefix='') + def lookup_vf_attribute (workitem, att_name, options={}) + prefix = options[:prefix] || '' prefix = "#{prefix.to_s}-" if prefix != '' - v = lookup_attribute("#{prefix}#{att_name}", workitem) + v = lookup_attribute( + "#{prefix}#{att_name}", workitem, options) return v if v - v = lookup_attribute("#{prefix}variable-#{att_name}", workitem) + v = lookup_attribute( + "#{prefix}variable-#{att_name}", workitem, options) return lookup_variable(v) if v - v = lookup_attribute("#{prefix}field-#{att_name}", workitem) + v = lookup_attribute( + "#{prefix}field-#{att_name}", workitem, options) return workitem.attributes[v] if v nil end @@ -636,10 +672,10 @@ # # Some eye candy # def to_s - s = "* #{@fei.to_debug_s}" + s = "* #{@fei.to_debug_s} [#{self.class.name}]" s << "\n `--p--> #{@parent_id.to_debug_s}" \ if @parent_id s << "\n `--e--> #{@environment_id.to_debug_s}" \