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

Returns:

  • (Object)

    the current value of colorizer


46
47
48
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46

def colorizer
  @colorizer
end

#returnedObject

Returns the value of attribute returned

Returns:

  • (Object)

    the current value of returned


46
47
48
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46

def returned
  @returned
end

#ruby_astObject

Returns the value of attribute ruby_ast

Returns:

  • (Object)

    the current value of ruby_ast


46
47
48
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46

def ruby_ast
  @ruby_ast
end

#traceObject

Returns the value of attribute trace

Returns:

  • (Object)

    the current value of trace


46
47
48
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46

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.

Returns:

  • (Hash)

    a map for => color


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

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.

Returns:

  • (String)

    a Rainbow colorized version of ruby


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

def colorize(color_scheme = COLOR_SCHEME)
  map = color_map(color_scheme)
  ast.loc.expression.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.

Returns:

  • (Hash)

    a map for => matched?, depth-first


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

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

Returns:

  • (Boolean)

    a value of `Trace#matched?` or `:not_visitable`


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

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