Class: RuboCop::YAMLDuplicationChecker::DuplicationCheckHandler Private

Inherits:
Psych::TreeBuilder
  • Object
show all
Defined in:
lib/rubocop/yaml_duplication_checker.rb

Overview

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.

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DuplicationCheckHandler

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 DuplicationCheckHandler.



15
16
17
18
# File 'lib/rubocop/yaml_duplication_checker.rb', line 15

def initialize(&block)
  super()
  @block = block
end

Instance Method Details

#end_mappingObject

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.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubocop/yaml_duplication_checker.rb', line 20

def end_mapping
  mapping_node = super
  # OPTIMIZE: Use a hash for faster lookup since there can
  # be quite a few keys at the top-level.
  keys = {}
  mapping_node.children.each_slice(2) do |key, _value|
    duplicate = keys[key.value]
    @block.call(duplicate, key) if duplicate
    keys[key.value] = key
  end
  mapping_node
end