lib/openwfe/workitem.rb in openwferu-0.9.3 vs lib/openwfe/workitem.rb in openwferu-0.9.4
- old
+ new
@@ -115,12 +115,65 @@
end
super(m, args)
end
+ #
+ # Produces a deep copy of the workitem
+ #
def dup
return OpenWFE::fulldup(self)
end
+
+ #
+ # A smarter alternative to
+ #
+ # value = workitem.attributes[x]
+ #
+ # Via this method, nested values can be reached. For example :
+ #
+ # wi = InFlowWorkItem.new()
+ # wi.attributes = {
+ # "field0" => "value0",
+ # "field1" => [ 0, 1, 2, 3, [ "a", "b", "c" ]],
+ # "field2" => {
+ # "a" => "AA",
+ # "b" => "BB",
+ # "c" => [ "C0", "C1", "C3" ]
+ # },
+ # "field3" => 3,
+ # "field99" => nil
+ # }
+ #
+ # will verify the following assertions :
+ #
+ # assert wi.lookup_attribute("field3") == 3
+ # assert wi.lookup_attribute("field1.1") == 1
+ # assert wi.lookup_attribute("field1.4.1") == "b"
+ # assert wi.lookup_attribute("field2.c.1") == "C1"
+ #
+ def lookup_attribute (key)
+ OpenWFE.lookup_attribute(@attributes, key)
+ end
+
+ #
+ # The partner to the lookup_attribute() method. Behaves like it.
+ #
+ def has_attribute? (key)
+ OpenWFE.has_attribute?(@attributes, key)
+ end
+
+ #
+ # set_attribute() accomodates itself with nested key constructs.
+ #
+ def set_attribute (key, value)
+ OpenWFE.set_attribute(@attributes, key, value)
+ end
+
+ alias :lookup_field :lookup_attribute
+ alias :has_field? :has_attribute?
+ alias :set_field :set_attribute
+
end
#
# The common parent class for InFlowWorkItem and CancelItem.
#