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.



24
25
26
27
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 24

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

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/ndr_dev_support/rubocop/range_augmenter.rb', line 12

def filename
  @filename
end

Class Method Details

.augmented_lines_for(file_ranges) ⇒ Object



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

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



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

def augmented_lines
  root  = Parser::CurrentRuby.parse IO.read(filename)
  nodes = extract_augmenting_nodes(root)

  lines_covering(@lines, nodes)
end