Class: RuboCop::AST::NodePattern::Compiler::Debug::Colorizer::Result Private

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubocop/ast/node_pattern/compiler/debug.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.

Result of a NodePattern run against a particular AST Consider constructor is private

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorizerObject

Returns the value of attribute colorizer



48
49
50
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 48

def colorizer
  @colorizer
end

#returnedObject

Returns the value of attribute returned



48
49
50
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 48

def returned
  @returned
end

#ruby_astObject

Returns the value of attribute ruby_ast



48
49
50
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 48

def ruby_ast
  @ruby_ast
end

#traceObject

Returns the value of attribute trace



48
49
50
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 48

def trace
  @trace
end

Instance Method Details

#color_map(color_scheme = COLOR_SCHEME) ⇒ Hash

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 map for => color.



58
59
60
61
62
63
64
65
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 58

def color_map(color_scheme = COLOR_SCHEME)
  @color_map ||=
    match_map
    .transform_values { |matched| color_scheme.fetch(matched) }
    .map { |node, color| color_map_for(node, color) }
    .inject(:merge)
    .tap { |h| h.default = color_scheme.fetch(:not_visitable) }
end

#colorize(color_scheme = COLOR_SCHEME) ⇒ String

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 Rainbow colorized version of ruby.



50
51
52
53
54
55
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 50

def colorize(color_scheme = COLOR_SCHEME)
  map = color_map(color_scheme)
  ast.source_range.source_buffer.source.chars.map.with_index do |char, i|
    Rainbow(char).color(map[i])
  end.join
end

#match_mapHash

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 map for => matched?, depth-first.



68
69
70
71
72
73
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 68

def match_map
  @match_map ||=
    ast
    .each_node
    .to_h { |node| [node, matched?(node)] }
end

#matched?(node) ⇒ Boolean

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 value of ‘Trace#matched?` or `:not_visitable`.



76
77
78
79
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 76

def matched?(node)
  id = colorizer.compiler.node_ids.fetch(node) { return :not_visitable }
  trace.matched?(id)
end