class CapistranoChewy::DiffParser

Constants

CHANGED_FILE_PATTERN
NEW_OR_REMOVED_FILE_PATTERN

Public Class Methods

parse(diff, current_path, release_path) click to toggle source
# File lib/capistrano-chewy/diff_parser.rb, line 21
def parse(diff, current_path, release_path)
  return Result.new if current_path == release_path

  diff.split("\n").each_with_object(Result.new) do |line, result|
    # File was changed
    CHANGED_FILE_PATTERN.match(line) do |match|
      result.changed << match[1]
      next
    end

    # File was removed or added
    NEW_OR_REMOVED_FILE_PATTERN.match(line) do |match|
      # if file placed in current path, then it was removed from the release path
      if match[1] == current_path.chomp(File::SEPARATOR)
        result.removed << File.join(match[1], match[2])
      else
        result.added << File.join(match[1], match[2])
      end
    end
  end
end