Class: Puppet::Pops::Lookup::ExplainNode

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/lookup/explainer.rb

Overview

The ExplainNode contains information of a specific node in a tree traversed during lookup. The tree can be traversed using the ‘parent` and `branches` attributes of each node.

Each leaf node contains information about what happened when the leaf of the branch was traversed.

Direct Known Subclasses

ExplainMergeSource, ExplainTreeNode, Explainer

Instance Method Summary collapse

Instance Method Details

#branchesObject



11
12
13
# File 'lib/puppet/pops/lookup/explainer.rb', line 11

def branches
  @branches ||= []
end

#dump_on(io, indent, first_indent) ⇒ Object



42
43
44
# File 'lib/puppet/pops/lookup/explainer.rb', line 42

def dump_on(io, indent, first_indent)
  dump_texts(io, indent)
end

#dump_texts(io, indent) ⇒ Object



46
47
48
# File 'lib/puppet/pops/lookup/explainer.rb', line 46

def dump_texts(io, indent)
  @texts.each { |text| io << indent << text << "\n" } if instance_variable_defined?(:@texts)
end

#explainObject



21
22
23
24
25
# File 'lib/puppet/pops/lookup/explainer.rb', line 21

def explain
  io = ''
  dump_on(io, '', '')
  io
end

#inspectObject



27
28
29
# File 'lib/puppet/pops/lookup/explainer.rb', line 27

def inspect
  to_s
end

#text(text) ⇒ Object



37
38
39
40
# File 'lib/puppet/pops/lookup/explainer.rb', line 37

def text(text)
  @texts ||= []
  @texts << text
end

#to_hashObject



15
16
17
18
19
# File 'lib/puppet/pops/lookup/explainer.rb', line 15

def to_hash
  hash = {}
  hash[:branches] = @branches.map {|b| b.to_hash} unless @branches.nil? || @branches.empty?
  hash
end

#to_sObject



31
32
33
34
35
# File 'lib/puppet/pops/lookup/explainer.rb', line 31

def to_s
  s = self.class.name
  s = "#{s} with #{@branches.size} branches" unless @branches.nil?
  s
end