module Guard::Cucumber::Focuser

def append_line_numbers_to_path(line_numbers, path)

Returns:
  • (String) - the string containing the path appended with the

Parameters:
  • path (String) -- the path that will receive the appended line
  • line_numbers (Array) -- the line numbers to append to
def append_line_numbers_to_path(line_numbers, path)
  line_numbers.each { |num| path += ":" + num.to_s }
  path
end

def focus(paths, focus_tag)

Returns:
  • (Array) - the updated paths

Parameters:
  • focus_tag (String) -- the focus tag to look for in each path
  • paths (Array) -- the locations of the feature files
def focus(paths, focus_tag)
  return false if paths.empty?
  paths.inject([]) do |updated_paths, path|
    focused_line_numbers = scan_path_for_focus_tag(path, focus_tag)
    if focused_line_numbers.empty?
      updated_paths << path
    else
      updated_paths << append_line_numbers_to_path(
        focused_line_numbers, path
      )
    end
    updated_paths
  end
end

def scan_path_for_focus_tag(path, focus_tag)

Returns:
  • (Array) - the line numbers that include the focus tag

Parameters:
  • focus_tag (String) -- the focus tag to look for in each path
  • path (String) -- the file path to search
def scan_path_for_focus_tag(path, focus_tag)
  return [] if File.directory?(path) || path.include?(":")
  line_numbers = []
  File.open(path, "r") do |file|
    while (line = file.gets)
      if line.include?(focus_tag)
        line_numbers << file.lineno
      end
    end
  end
  line_numbers
end