Module: Gem::Comparator::Monitor
- Defined in:
- lib/rubygems/comparator/monitor.rb
Class Method Summary collapse
- .compact_files_diff(prev_file, curr_file) ⇒ Object
- .files_executability_changes(prev_file, curr_file) ⇒ Object
- .files_permissions_changes(prev_file, curr_file) ⇒ Object
- .files_shebang_changes(prev_file, curr_file) ⇒ Object
- .lines_changed(prev_file, curr_file) ⇒ Object
- .new_file_executability(file) ⇒ Object
- .new_file_permissions(file) ⇒ Object
- .new_file_shebang(file) ⇒ Object
Class Method Details
.compact_files_diff(prev_file, curr_file) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubygems/comparator/monitor.rb', line 29 def self.(prev_file, curr_file) = DirUtils.(prev_file) = DirUtils.(curr_file) if != " (!) New permissions: " + "#{} -> #{}" else '' end end |
.files_shebang_changes(prev_file, curr_file) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
8 9 10 11 12 13 14 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubygems/comparator/monitor.rb', line 41 def self.(file) = DirUtils.(file) if != '100644' unless (DirUtils.gem_bin_file?(file) && == '100755') return " (!) Unexpected permissions: #{}" end end '' end |
.new_file_shebang(file) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# 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 |