Class: NdrDevSupport::Rubocop::RangeAugmenter

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_dev_support/rubocop/range_augmenter.rb

Overview

For a given file, and set of line ranges, computes a list of all lines covered, expanding the ranges to include full method defintions, and class/module headers.

Constant Summary collapse

MODULE_TYPES =
[:module, :class].freeze
METHOD_TYPES =
[:def, :defs].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, ranges) ⇒ RangeAugmenter

Returns a new instance of RangeAugmenter.



22
23
24
25
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 22

def initialize(filename, ranges)
  @filename = filename
  @lines    = ranges.map(&:to_a).flatten
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 10

def filename
  @filename
end

Class Method Details

.augmented_lines_for(file_ranges) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 13

def augmented_lines_for(file_ranges)
  output = {}
  file_ranges.each do |file, ranges|
    output[file] = new(file, ranges).lines
  end
  output
end

Instance Method Details

#augmented_linesObject



27
28
29
30
31
32
33
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 27

def augmented_lines
  require 'parser/current'
  root  = Parser::CurrentRuby.parse IO.read(filename)
  nodes = extract_augmenting_nodes(root)

  lines_covering(@lines, nodes)
end