module Gem::Comparator::Monitor

Public Class Methods

compact_files_diff(prev_file, curr_file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 16
def self.compact_files_diff(prev_file, curr_file)
  changes = ''
  Diffy::Diff.new(
    prev_file, curr_file, :source => 'files', :context => 0
  ).each do |line|
    case line
    when /^\+/ then changes << Rainbow('+').green
    when /^-/ then changes << Rainbow('-').red
    end
  end
  changes
end
files_executability_changes(prev_file, curr_file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 52
def self.files_executability_changes(prev_file, curr_file)
  prev_executable = File.stat(prev_file).executable?
  curr_executable = File.stat(curr_file).executable?

  if !prev_executable && curr_executable
    "  (!) File is now executable!"
  elsif prev_executable && !curr_executable
    "  (!) File is no longer executable!"
  else
    ''
  end
end
files_permissions_changes(prev_file, curr_file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 29
def self.files_permissions_changes(prev_file, curr_file)
  prev_permissions = DirUtils.file_permissions(prev_file)
  curr_permissions = DirUtils.file_permissions(curr_file)

  if prev_permissions != curr_permissions
    "  (!) New permissions: " +
    "#{prev_permissions} -> #{curr_permissions}"
  else
    ''
  end
end
files_shebang_changes(prev_file, curr_file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 77
def self.files_shebang_changes(prev_file, curr_file)
  return '' if DirUtils.files_same_first_line?(prev_file, curr_file)

  prev_has_shebang = DirUtils.file_has_shebang? prev_file
  curr_has_shebang = DirUtils.file_has_shebang? curr_file

  if prev_has_shebang && !curr_has_shebang
      "  (!) Shebang probably lost: #{DirUtils.file_first_line(prev_file)}"
  elsif !prev_has_shebang && curr_has_shebang
      "  (!) Shebang probably added: #{DirUtils.file_first_line(curr_file)}"
  elsif prev_has_shebang && curr_has_shebang
      "  (!) Shebang probably changed: " +
      "#{first_lines[prev_file]} -> #{DirUtils.file_first_line(curr_file)}"
  else
      ''
  end
end
lines_changed(prev_file, curr_file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 8
def self.lines_changed(prev_file, curr_file)
  line = compact_files_diff(prev_file, curr_file)
  return '' if line.empty?
  plus = "+#{line.count('+')}"
  minus = "-#{line.count('-')}"
  "#{Rainbow(plus).green}/#{Rainbow(minus).red}"
end
new_file_executability(file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 65
def self.new_file_executability(file)
  file_executable = File.stat(file).executable?

  if file_executable && !DirUtils.gem_bin_file?(file)
    "  (!) File is executable"
  elsif !file_executable && DirUtils.gem_bin_file?(file)
    "  (!) File is not executable"
  else
    ''
  end
end
new_file_permissions(file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 41
def self.new_file_permissions(file)
  file_permissions = DirUtils.file_permissions(file)

  if file_permissions != '100644'
    unless (DirUtils.gem_bin_file?(file) && file_permissions == '100755')
      return "  (!) Unexpected permissions: #{file_permissions}"
    end
  end
  ''
end
new_file_shebang(file) click to toggle source
# File lib/rubygems/comparator/monitor.rb, line 95
def self.new_file_shebang(file)
  file_has_shebang = DirUtils.file_has_shebang? file

  if file_has_shebang
    "  (!) Shebang found: #{DirUtils.file_first_line(file)}"
  else
    ''
  end
end