Class: Puppet::Pops::Lookup::ExplainTreeNode Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExplainNode

#branches, #dump_on, #dump_texts, #explain, #inspect, #text

Constructor Details

#initialize(parent) ⇒ ExplainTreeNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ExplainTreeNode.



56
57
58
59
# File 'lib/puppet/pops/lookup/explainer.rb', line 56

def initialize(parent)
  @parent = parent
  @event = nil
end

Instance Attribute Details

#eventObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/puppet/pops/lookup/explainer.rb', line 53

def event
  @event
end

#keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/puppet/pops/lookup/explainer.rb', line 54

def key
  @key
end

#parentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/puppet/pops/lookup/explainer.rb', line 53

def parent
  @parent
end

#valueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/puppet/pops/lookup/explainer.rb', line 53

def value
  @value
end

Instance Method Details

#dump_outcome(io, indent) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/puppet/pops/lookup/explainer.rb', line 111

def dump_outcome(io, indent)
  case @event
  when :not_found
    io << indent << 'No such key: "' << @key << "\"\n"
  when :found, :found_in_overrides, :found_in_defaults
    io << indent << 'Found key: "' << @key << '" value: '
    dump_value(io, indent, @value)
    io << ' in overrides' if @event == :found_in_overrides
    io << ' in defaults' if @event == :found_in_defaults
    io << "\n"
  end
  dump_texts(io, indent)
end

#dump_value(io, indent, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/puppet/pops/lookup/explainer.rb', line 125

def dump_value(io, indent, value)
  case value
  when Hash
    io << '{'
    unless value.empty?
      inner_indent = increase_indent(indent)
      value.reduce("\n") do |sep, (k, v)|
        io << sep << inner_indent
        dump_value(io, inner_indent, k)
        io << ' => '
        dump_value(io, inner_indent, v)
        ",\n"
      end
      io << "\n" << indent
    end
    io << '}'
  when Array
    io << '['
    unless value.empty?
      inner_indent = increase_indent(indent)
      value.reduce("\n") do |sep, v|
        io << sep << inner_indent
        dump_value(io, inner_indent, v)
        ",\n"
      end
      io << "\n" << indent
    end
    io << ']'
  else
    io << value.inspect
  end
end

#found(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
# File 'lib/puppet/pops/lookup/explainer.rb', line 73

def found(key, value)
  @key = key.to_s
  @value = value
  @event = :found
end

#found_in_defaults(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
71
# File 'lib/puppet/pops/lookup/explainer.rb', line 67

def found_in_defaults(key, value)
  @key = key.to_s
  @value = value
  @event = :found_in_defaults
end

#found_in_overrides(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
# File 'lib/puppet/pops/lookup/explainer.rb', line 61

def found_in_overrides(key, value)
  @key = key.to_s
  @value = value
  @event = :found_in_overrides
end

#increase_indent(indent) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
# File 'lib/puppet/pops/lookup/explainer.rb', line 93

def increase_indent(indent)
  indent + '  '
end

#location_not_foundObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



89
90
91
# File 'lib/puppet/pops/lookup/explainer.rb', line 89

def location_not_found
  @event = :location_not_found
end

#not_found(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
87
# File 'lib/puppet/pops/lookup/explainer.rb', line 84

def not_found(key)
  @key = key.to_s
  @event = :not_found
end

#result(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
# File 'lib/puppet/pops/lookup/explainer.rb', line 79

def result(value)
  @value = value
  @event = :result
end

#to_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
100
101
102
103
104
105
# File 'lib/puppet/pops/lookup/explainer.rb', line 97

def to_hash
  hash = super
  hash[:key] = @key unless @key.nil?
  hash[:value] = @value if [:found, :found_in_defaults, :found_in_overrides, :result].include?(@event)
  hash[:event] = @event unless @event.nil?
  hash[:texts] = @texts unless @texts.nil?
  hash[:type] = type
  hash
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/puppet/pops/lookup/explainer.rb', line 158

def to_s
  "#{self.class.name}: #{@key}, #{@event}"
end

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



107
108
109
# File 'lib/puppet/pops/lookup/explainer.rb', line 107

def type
  :root
end