Class: RuboCop::AST::NodePattern::Compiler::Debug::Colorizer::Result Private
- Inherits:
-
Struct
- Object
- Struct
- RuboCop::AST::NodePattern::Compiler::Debug::Colorizer::Result
- 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
-
#colorizer ⇒ Object
Returns the value of attribute colorizer.
-
#returned ⇒ Object
Returns the value of attribute returned.
-
#ruby_ast ⇒ Object
Returns the value of attribute ruby_ast.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
-
#color_map(color_scheme = COLOR_SCHEME) ⇒ Hash
private
A map for => color.
-
#colorize(color_scheme = COLOR_SCHEME) ⇒ String
private
A Rainbow colorized version of ruby.
-
#match_map ⇒ Hash
private
A map for => matched?, depth-first.
-
#matched?(node) ⇒ Boolean
private
A value of ‘Trace#matched?` or `:not_visitable`.
Instance Attribute Details
#colorizer ⇒ Object
Returns the value of attribute colorizer
46 47 48 |
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46 def colorizer @colorizer end |
#returned ⇒ Object
Returns the value of attribute returned
46 47 48 |
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46 def returned @returned end |
#ruby_ast ⇒ Object
Returns the value of attribute ruby_ast
46 47 48 |
# File 'lib/rubocop/ast/node_pattern/compiler/debug.rb', line 46 def ruby_ast @ruby_ast end |
#trace ⇒ Object
Returns the value of attribute 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.
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.
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.source_range.source_buffer.source.chars.map.with_index do |char, i| Rainbow(char).color(map[i]) end.join end |
#match_map ⇒ 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 => 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`.
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 |