In Files

  • test-unit-3.3.7/lib/test/unit/code-snippet-fetcher.rb

Parent

Methods

Class/Module Index [+]

Quicksearch

Test::Unit::CodeSnippetFetcher

Public Class Methods

new() click to toggle source
 
               # File test-unit-3.3.7/lib/test/unit/code-snippet-fetcher.rb, line 4
def initialize
  @sources = {}
end
            

Public Instance Methods

fetch(path, line, options={}) click to toggle source
 
               # File test-unit-3.3.7/lib/test/unit/code-snippet-fetcher.rb, line 8
def fetch(path, line, options={})
  n_context_line = options[:n_context_line] || 3
  lines = source(path)
  return [] if lines.nil?
  min_line = [line - n_context_line, 1].max
  max_line = [line + n_context_line, lines.length].min
  window = min_line..max_line
  window.collect do |n|
    attributes = {:target_line? => (n == line)}
    [n, lines[n - 1].chomp, attributes]
  end
end
            
source(path) click to toggle source
 
               # File test-unit-3.3.7/lib/test/unit/code-snippet-fetcher.rb, line 21
def source(path)
  @sources[path] ||= read_source(path)
end