Class: Psych::Visitors::YAMLTree::Registrar

Inherits:
Object
  • Object
show all
Defined in:
lib/psych/visitors/yaml_tree.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeRegistrar

Returns a new instance of Registrar.



17
18
19
20
21
22
# File 'lib/psych/visitors/yaml_tree.rb', line 17

def initialize
  @obj_to_id   = {}
  @obj_to_node = {}
  @targets     = []
  @counter     = 0
end

Instance Method Details

#id_for(target) ⇒ Object



36
37
38
# File 'lib/psych/visitors/yaml_tree.rb', line 36

def id_for target
  @obj_to_id[target.object_id] ||= (@counter += 1)
end

#key?(target) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/psych/visitors/yaml_tree.rb', line 30

def key? target
  @obj_to_node.key? target.object_id
rescue NoMethodError
  false
end

#node_for(target) ⇒ Object



40
41
42
# File 'lib/psych/visitors/yaml_tree.rb', line 40

def node_for target
  @obj_to_node[target.object_id]
end

#register(target, node) ⇒ Object



24
25
26
27
28
# File 'lib/psych/visitors/yaml_tree.rb', line 24

def register target, node
  return unless target.respond_to? :object_id
  @targets << target
  @obj_to_node[target.object_id] = node
end