* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
ids to be sequential numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a75922010f
commit
7a68f53dc6
@ -1,3 +1,8 @@
|
|||||||
|
Fri Feb 8 08:50:42 2013 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
|
||||||
|
ids to be sequential numbers.
|
||||||
|
|
||||||
Fri Feb 8 07:47:56 2013 Eric Hodel <drbrain@segment7.net>
|
Fri Feb 8 07:47:56 2013 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/rubygems/package/old.rb: Disallow installation of old-format
|
* lib/rubygems/package/old.rb: Disallow installation of old-format
|
||||||
|
@ -8,6 +8,30 @@ module Psych
|
|||||||
# builder.tree # => #<Psych::Nodes::Stream .. }
|
# builder.tree # => #<Psych::Nodes::Stream .. }
|
||||||
#
|
#
|
||||||
class YAMLTree < Psych::Visitors::Visitor
|
class YAMLTree < Psych::Visitors::Visitor
|
||||||
|
class Registrar # :nodoc:
|
||||||
|
def initialize
|
||||||
|
@obj_to_id = {}
|
||||||
|
@obj_to_node = {}
|
||||||
|
@counter = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def register target, node
|
||||||
|
@obj_to_node[target.object_id] = node
|
||||||
|
end
|
||||||
|
|
||||||
|
def key? target
|
||||||
|
@obj_to_node.key? target.object_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def id_for target
|
||||||
|
@obj_to_id[target.object_id] ||= (@counter += 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def node_for target
|
||||||
|
@obj_to_node[target.object_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
attr_reader :started, :finished
|
attr_reader :started, :finished
|
||||||
alias :finished? :finished
|
alias :finished? :finished
|
||||||
alias :started? :started
|
alias :started? :started
|
||||||
@ -17,7 +41,7 @@ module Psych
|
|||||||
@started = false
|
@started = false
|
||||||
@finished = false
|
@finished = false
|
||||||
@emitter = emitter
|
@emitter = emitter
|
||||||
@st = {}
|
@st = Registrar.new
|
||||||
@ss = ss
|
@ss = ss
|
||||||
@options = options
|
@options = options
|
||||||
@coders = []
|
@coders = []
|
||||||
@ -72,9 +96,9 @@ module Psych
|
|||||||
|
|
||||||
def accept target
|
def accept target
|
||||||
# return any aliases we find
|
# return any aliases we find
|
||||||
if @st.key? target.object_id
|
if @st.key? target
|
||||||
oid = target.object_id
|
oid = @st.id_for target
|
||||||
node = @st[oid]
|
node = @st.node_for target
|
||||||
anchor = oid.to_s
|
anchor = oid.to_s
|
||||||
node.anchor = anchor
|
node.anchor = anchor
|
||||||
return @emitter.alias anchor
|
return @emitter.alias anchor
|
||||||
@ -410,7 +434,7 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
def register target, yaml_obj
|
def register target, yaml_obj
|
||||||
@st[target.object_id] = yaml_obj
|
@st.register target, yaml_obj
|
||||||
yaml_obj
|
yaml_obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user