diff --git a/lib/sof/members.rb b/lib/sof/members.rb index 1b47832a..8973a2b7 100644 --- a/lib/sof/members.rb +++ b/lib/sof/members.rb @@ -14,15 +14,20 @@ module Sof def add object , level return if is_value?(object) - if( occurence = @objects[object] ) + if( occurence = @objects[object.object_id] ) #puts "reset level #{level} at #{occurence.level}" - occurence.level = level if occurence.level > level - occurence.referenced = @counter - @counter = @counter + 1 + if occurence.level > level + occurence.level = level + end + unless occurence.referenced + #puts "referencing #{@counter} , at level #{level}/#{occurence.level} " + occurence.referenced = @counter + @counter = @counter + 1 + end return end o = Occurence.new( object , level ) - @objects[object] = o + @objects[object.object_id] = o attributes = attributes_for(object) attributes.each do |a| val = get_value( object , a) diff --git a/lib/sof/node.rb b/lib/sof/node.rb index 88c42409..b09463b6 100644 --- a/lib/sof/node.rb +++ b/lib/sof/node.rb @@ -16,12 +16,13 @@ module Sof end class SimpleNode < Node - def initialize data - super(nil) + def initialize data , ref = nil + super(ref) @data = data end attr_reader :data def out io , level + super io.write(data) end end diff --git a/lib/sof/writer.rb b/lib/sof/writer.rb index d3f60ced..28131041 100644 --- a/lib/sof/writer.rb +++ b/lib/sof/writer.rb @@ -16,10 +16,10 @@ module Sof if is_value?(object) return SimpleNode.new(object.to_sof()) end - occurence = @members.objects[object] + occurence = @members.objects[object.object_id] raise "no object #{object}" unless occurence if(level > occurence.level ) - #puts "level #{level} at #{occurence.level}" + #puts "ref #{occurence.referenced} level #{level} at #{occurence.level}" return SimpleNode.new("*#{occurence.referenced}") end ref = occurence.referenced @@ -32,7 +32,7 @@ module Sof def object_sof_node( object , level , ref) if( object.is_a? Class ) - return SimpleNode.new( object.name ) + return SimpleNode.new( object.name , ref ) end head = object.class.name + "(" atts = {}