lib/openwfe/utils.rb in openwferu-0.9.16 vs lib/openwfe/utils.rb in openwferu-0.9.17
- old
+ new
@@ -1,8 +1,8 @@
#
#--
-# Copyright (c) 2005-2007, John Mettraux, OpenWFE.org
+# Copyright (c) 2005-2008, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -56,18 +56,10 @@
xmlElt.elements.detect { |elt| elt.name == elementName }
end
#
- # Used in tests, is equivalent to Perl's die() method.
- #
- def OpenWFE.die (text)
- puts text
- exit 1
- end
-
- #
# see
# http://wiki.rubygarden.org/Ruby/page/show/Make_A_Deep_Copy_Of_An_Object
#
# It's not perfect (that's why fulldup() uses it only in certain cases).
#
@@ -86,10 +78,14 @@
# an automatic dup implementation attempt
#
def OpenWFE.fulldup (object)
return nil if object == nil
+
+ return object.fulldup if object.respond_to?("fulldup")
+ # trusting client objects providing a fulldup() implementation
+ # Tomaso Tosolini 2007.12.11
return object if object.kind_of?(Float)
return object if object.kind_of?(Fixnum)
return object if object.kind_of?(TrueClass)
return object if object.kind_of?(FalseClass)
@@ -113,11 +109,11 @@
o = nil
begin
o = object.class.new
- rescue ArgumentError
+ rescue ArgumentError => ae
return deep_clone(object)
end
#
# some kind of collection ?
@@ -268,11 +264,11 @@
#
# Sets the name of the current thread (the attribute :name if it is
# a ruby thread, the java thread name if we're in JRuby)
#
- def set_current_thread_name (name)
+ def OpenWFE.set_current_thread_name (name)
if defined?(JRUBY_VERSION)
require 'java'
java.lang.Thread.current_thread.name = "#{name} (Ruby Thread)"
else
Thread.current[:name] = name
@@ -348,10 +344,13 @@
end
end
#
+ # (2008.03.12 Deprecated, kept here for a while
+ # for backward compatibility)
+ #
# A simple Hash that accepts String or Symbol as lookup keys []
#
class SymbolHash < Hash
def [] (key)
super(key.to_s)
@@ -470,9 +469,32 @@
return
end
container = lookup_attribute(container, key[0..i-1])
container[key[i+1..-1]] = value
+ end
+
+ #
+ # This method is used within the InFlowWorkItem and the CsvTable classes.
+ #
+ def OpenWFE.unset_attribute (container, key)
+
+ i = key.rindex(".")
+
+ if not i
+ container.delete key
+ return
+ end
+
+ container = lookup_attribute container, key[0..i-1]
+
+ if container.is_a?(Array)
+
+ container.delete_at key[i+1..-1].to_i
+ else
+
+ container.delete key[i+1..-1]
+ end
end
#
# Returns true if this host is currently online (has access to the web /
# internet).