Class: Puppet::Pops::Lookup::ExplainMerge

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

Instance Attribute Summary

Attributes inherited from ExplainTreeNode

#event, #key, #parent, #value

Instance Method Summary collapse

Methods inherited from ExplainTreeNode

#dump_outcome, #dump_value, #found, #found_in_defaults, #found_in_overrides, #increase_indent, #module_not_found, #not_found, #path_not_found, #result

Methods inherited from ExplainNode

#branches, #to_s

Constructor Details

#initialize(parent, merge) ⇒ ExplainMerge

Returns a new instance of ExplainMerge.



160
161
162
163
# File 'lib/puppet/pops/lookup/explainer.rb', line 160

def initialize(parent, merge)
  super(parent)
  @merge = merge
end

Instance Method Details

#dump_on(io, indent, first_indent) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/puppet/pops/lookup/explainer.rb', line 165

def dump_on(io, indent, first_indent)
  # It's pointless to report a merge where there's only one branch
  return branches[0].dump_on(io, indent, first_indent) if branches.size == 1

  io << first_indent << 'Merge strategy ' << @merge.class.key << "\n"
  indent = increase_indent(indent)
  options = options_wo_strategy
  unless options.nil?
    io << indent << 'Options: '
    dump_value(io, indent, options)
    io << "\n"
  end
  branches.each {|b| b.dump_on(io, indent, indent)}
  if @event == :result
    io << indent << 'Merged result: '
    dump_value(io, indent, @value)
    io << "\n"
  end
end

#options_wo_strategyObject



198
199
200
201
202
203
204
205
# File 'lib/puppet/pops/lookup/explainer.rb', line 198

def options_wo_strategy
  options = @merge.options
  if !options.nil? && options.include?('strategy')
    options = options.dup
    options.delete('strategy')
  end
  options.empty? ? nil : options
end

#to_hashObject



185
186
187
188
189
190
191
192
# File 'lib/puppet/pops/lookup/explainer.rb', line 185

def to_hash
  return branches[0].to_hash if branches.size == 1
  hash = super
  hash[:merge] = @merge.class.key
  options = options_wo_strategy
  hash[:options] = options unless options.nil?
  hash
end

#typeObject



194
195
196
# File 'lib/puppet/pops/lookup/explainer.rb', line 194

def type
  :merge
end