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

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

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

Returns a new instance of ExplainTreeNode.



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

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

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



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

def event
  @event
end

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#dump_outcome(io, indent) ⇒ Object



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

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



124
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
# File 'lib/puppet/pops/lookup/explainer.rb', line 124

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



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

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

#found_in_defaults(key, value) ⇒ Object



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

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

#found_in_overrides(key, value) ⇒ Object



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

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

#increase_indent(indent) ⇒ Object



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

def increase_indent(indent)
  indent + '  '
end

#location_not_foundObject



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

def location_not_found
  @event = :location_not_found
end

#not_found(key) ⇒ Object



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

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

#result(value) ⇒ Object



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

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

#to_hashObject



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

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



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

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

#typeObject



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

def type
  :root
end