Class: Kaisoku::MethodMap
- Inherits:
-
Object
- Object
- Kaisoku::MethodMap
- Defined in:
- lib/kaisoku/method_map.rb
Constant Summary collapse
- TOP_LEVEL =
'__toplevel__'
Instance Method Summary collapse
- #checksums(path) ⇒ Object
-
#initialize(configuration: Configuration.new) ⇒ MethodMap
constructor
A new instance of MethodMap.
- #keys_for_lines(path, touched_lines) ⇒ Object
Constructor Details
#initialize(configuration: Configuration.new) ⇒ MethodMap
Returns a new instance of MethodMap.
10 11 12 |
# File 'lib/kaisoku/method_map.rb', line 10 def initialize(configuration: Configuration.new) @configuration = configuration end |
Instance Method Details
#checksums(path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kaisoku/method_map.rb', line 14 def checksums(path) absolute = @configuration.absolute_path(path) return {} unless File.file?(absolute) && File.extname(absolute) == '.rb' source = File.read(absolute) lines = source.lines ranges = method_ranges(source) ranges.to_h do |name, range| ["#{@configuration.relative_path(path)}##{name}", digest(lines[(range.begin - 1)..(range.end - 1)].join)] end.merge(top_level_checksum(path, lines, ranges.values)) rescue StandardError {} end |
#keys_for_lines(path, touched_lines) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kaisoku/method_map.rb', line 28 def keys_for_lines(path, touched_lines) absolute = @configuration.absolute_path(path) return [] unless File.file?(absolute) && File.extname(absolute) == '.rb' ranges = method_ranges(File.read(absolute)) touched = Array(touched_lines).map(&:to_i) keys = ranges.filter_map do |name, range| "#{@configuration.relative_path(path)}##{name}" if touched.any? { |line| range.cover?(line) } end keys << "#{@configuration.relative_path(path)}##{TOP_LEVEL}" if top_level_touched?(touched, ranges.values) keys rescue StandardError [] end |