lib/openwfe/flowexpressionid.rb in openwferu-0.9.5 vs lib/openwfe/flowexpressionid.rb in openwferu-0.9.6
- old
+ new
@@ -46,35 +46,56 @@
#
# FlowExpressionId
#
class FlowExpressionId
- attr_accessor \
- :owfe_version,
- :engine_id,
+ FIELDS = [
+ :owfe_version,
+ :engine_id,
:initial_engine_id,
- :workflow_definition_url,
+ :workflow_definition_url,
:workflow_definition_name,
:workflow_definition_revision,
:workflow_instance_id,
:expression_name,
:expression_id
+ ]
+ FIELDS.each { |f| attr_accessor f }
+
#
# A shortcut for fei.workflow_instance_id.
# There's also fei.parent_wfid.
#
alias :wfid :workflow_instance_id
#
- # overrides the classical to_s()
+ # Overrides the classical to_s()
#
def to_s ()
- return "(fei #{@owfe_version} #{@engine_id}/#{@initial_engine_id} #{@workflow_definition_url} #{@workflow_definition_name} #{@workflow_definition_revision} #{@workflow_instance_id} #{@expression_name} #{@expression_id})"
+ "(fei #{@owfe_version} #{@engine_id}/#{@initial_engine_id} #{@workflow_definition_url} #{@workflow_definition_name} #{@workflow_definition_revision} #{@workflow_instance_id} #{@expression_name} #{@expression_id})"
end
+ #
+ # Returns a hash version of this FlowExpressionId instance.
+ #
+ def to_h ()
+ h = {}
+ FIELDS.each { |f| h[f] = instance_eval("@#{f.to_s}") }
+ h
+ end
+
+ #
+ # Rebuilds a FlowExpressionId from its Hash representation.
+ #
+ def FlowExpressionId.from_h (h)
+ fei = FlowExpressionId.new
+ FIELDS.each { |f| fei.instance_variable_set("@#{f}", h[f]) }
+ fei
+ end
+
def hash ()
- return to_s().hash()
+ to_s().hash()
end
def == (other)
return false if not other.kind_of?(FlowExpressionId)