Class: Gem::Comparator::FileListComparator
- Inherits:
-
Base
- Object
- Base
- Gem::Comparator::FileListComparator
- Defined in:
- lib/rubygems/comparator/file_list_comparator.rb
Overview
Gem::Comparator::FileListComparator can compare file lists from gem's specs based on the given Gem::Package objects
To compare the files it needs to extract gem packages to options
Instance Method Summary collapse
-
#compare(packages, report, options = {}) ⇒ Object
Compare file lists for gem's Gem::Package objects in
packages
and writes the changes to thereport
. -
#initialize(ignore_group_writable = true) ⇒ FileListComparator
constructor
A new instance of FileListComparator.
Constructor Details
#initialize(ignore_group_writable = true) ⇒ FileListComparator
Returns a new instance of FileListComparator.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubygems/comparator/file_list_comparator.rb', line 18 def initialize(ignore_group_writable=true) expect(:packages) # We need diff begin IO.popen('diff --version') rescue Exception error('Calling `diff` command failed. Do you have it installed?') end @ignore_group_writable = ignore_group_writable end |
Instance Method Details
#compare(packages, report, options = {}) ⇒ Object
Compare file lists for gem's Gem::Package objects in packages
and writes the changes to the report
If options is set, it compares only that file list
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubygems/comparator/file_list_comparator.rb', line 38 def compare(packages, report, = {}) info 'Checking file lists...' @packages = packages # Check file lists from older versions to newer filter_params(SPEC_FILES_PARAMS, [:param]).each do |param| all_same = true packages.each_with_index do |pkg, index| unpacked_gem_dirs[packages[index].spec.version] = extract_gem(pkg, [:output]) next if index == 0 # File lists as arrays previous = value_from_spec(param, packages[index-1].spec) current = value_from_spec(param, pkg.spec) next unless (previous && current) vers = "#{packages[index-1].spec.version}->#{packages[index].spec.version}" deleted = previous - current added = current - previous same = current - added if [:brief] deleted, dirs_added = dir_changed(previous, current) end report[param].set_header "#{different} #{param}:" report[param][vers].section do set_header "#{Rainbow(packages[index-1].spec.version).cyan}->" + "#{Rainbow(packages[index].spec.version).cyan}:" nest('deleted').section do set_header '* Deleted:' puts deleted unless deleted.empty? end nest('added').section do set_header '* Added:' puts dirs_added if [:brief] end end # Add information about permissions, shebangs etc. report = check_added_files(param, vers, index, added, report, [:brief], [:diff]) report[param][vers]['changed'].set_header '* Changed:' report = check_same_files(param, vers, index, same, report, [:brief], [:diff]) same_files = report[param][vers]['changed']..empty? all_same = false unless same_files if previous == current && same_files && !all_same report[param][vers] << "#{Rainbow(packages[index-1].spec.version).cyan}->" + \ "#{Rainbow(packages[index].spec.version).cyan}: No change" end end if all_same && [:log_all] report[param].set_header "#{same} #{param}:" value = value_from_spec(param, @packages[0].spec) value = '[]' if value.empty? report[param] << value end end report end |