fix weird object bug

This commit is contained in:
Torsten Ruger 2014-08-18 12:49:38 +03:00
parent a3c9ab7e29
commit 9f292ba618
6 changed files with 13 additions and 14 deletions

View File

@ -13,8 +13,7 @@ module Sof
def add object , level def add object , level
return if is_value?(object) return if is_value?(object)
if( @objects.has_key?(object) ) if( occurence = @objects[object] )
occurence = @objects[object]
occurence.level = level if occurence.level > level occurence.level = level if occurence.level > level
return return
end end

View File

@ -48,13 +48,13 @@ module Sof
end end
def out io , level = 0 def out io , level = 0
io.write(@data) io.write(@data)
indent = " " * level indent = " " * (level + 1)
@children.each_with_index do |child , i| @children.each_with_index do |child , i|
k , v = child k , v = child
io.write "\n#{indent}" io.write "\n#{indent}"
io.write ".." k.out(io , level + 2)
k.out(io , level + 1) io.write " "
v.out(io , level + 1) v.out(io , level + 2)
end end
end end
end end

View File

@ -15,8 +15,8 @@ module Sof
end end
def attributes_for object def attributes_for object
attributes = object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @ atts = object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @
attributes - Volotile.attributes(object.class) atts - Volotile.attributes(object.class)
end end
end end

View File

@ -27,13 +27,13 @@ module Sof
def object_sof_node( object , level) def object_sof_node( object , level)
head = object.class.name + "(" head = object.class.name + "("
attributes = attributes_for(object) atts = attributes_for(object)
immediate , extended = attributes.partition {|a| is_value?(get_value(object , a) ) } immediate , extended = atts.partition {|a| is_value?(get_value(object , a) ) }
head += immediate.collect {|a| "#{a}: #{get_value(object , a).to_sof()}"}.join(", ") + ")" head += immediate.collect {|a| "#{a}: #{get_value(object , a).to_sof()}"}.join(", ") + ")"
node = ObjectNode.new(head) node = ObjectNode.new(head)
extended.each do |a| extended.each do |a|
val = get_value(object , a) val = get_value(object , a)
node.add( write.to_sof_node(a) , writer.to_sof_node(val) ) node.add( to_sof_node(a) , to_sof_node(val) )
end end
node node
end end

View File

@ -33,7 +33,7 @@ class BasicSof < MiniTest::Test
end end
def test_object_extra_array def test_object_extra_array
@out = Sof::Writer.write(ObjectWithAttributes.new.extra_array) @out = Sof::Writer.write(ObjectWithAttributes.new.extra_array)
check "#{OBJECT_STRING}" check "#{OBJECT_STRING}\n :extra -:sym\n -123"
end end
def test_simple_array def test_simple_array
@out = Sof::Writer.write([true, 1234]) @out = Sof::Writer.write([true, 1234])