Class: Gem::Comparator
- Inherits:
-
Object
- Object
- Gem::Comparator
- Includes:
- Utils
- Defined in:
- lib/rubygems/comparator.rb,
lib/rubygems/comparator/dependency_comparator.rb,
lib/rubygems/comparator/file_list_comparator.rb,
lib/rubygems/comparator/gemfile_comparator.rb,
lib/rubygems/comparator/spec_comparator.rb,
lib/rubygems/comparator/report/entry.rb,
lib/rubygems/comparator/dir_utils.rb,
lib/rubygems/comparator/version.rb,
lib/rubygems/comparator/monitor.rb,
lib/rubygems/comparator/report.rb,
lib/rubygems/comparator/utils.rb,
lib/rubygems/comparator/base.rb
Overview
Gem::Comparator compares different version of the given gem. It can compare spec values as well as file lists or Gemfiles
Defined Under Namespace
Modules: DirUtils, Monitor, Utils Classes: Base, DependencyComparator, FileListComparator, GemfileComparator, Report, SpecComparator
Constant Summary collapse
- VERSION =
'1.2.1'
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#report ⇒ Object
Returns the value of attribute report.
Instance Method Summary collapse
-
#compare_versions(gem_name, versions) ⇒ Object
Compare versions.
-
#initialize(options) ⇒ Comparator
constructor
Set the working dir and process options.
- #print_results ⇒ Object
Constructor Details
#initialize(options) ⇒ Comparator
Set the working dir and process options
Creates temporal directory if the gem files shouldn't be kept
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubygems/comparator.rb', line 32 def initialize() info "gem-compare in #{VERSION}" unless [:keep_all] [:output] = Dir.mktmpdir end if [:param] && !param_exists?([:param]) error 'Invalid parameter.' end if [:no_color] Rainbow.enabled = false end # Let's override platforms with the latest one if # a platform has been specified via --platform if [:added_platform] Gem.platforms = [Gem.platforms.last] [:platform] = Gem.platforms.last.to_s info "Overriding platform to: #{[:platform]}" end @options = # Results from the comparison @report = Gem::Comparator::Report.new end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/rubygems/comparator.rb', line 25 def @options end |
#report ⇒ Object
Returns the value of attribute report.
25 26 27 |
# File 'lib/rubygems/comparator.rb', line 25 def report @report end |
Instance Method Details
#compare_versions(gem_name, versions) ⇒ Object
Compare versions
Compares file lists, requirements, other meta data
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 105 |
# File 'lib/rubygems/comparator.rb', line 66 def compare_versions(gem_name, versions) # Expand versions (<=, >=, ~>) and sort them compared_versions = (gem_name, versions) if versions.include?('_') && (compared_versions.size == 1) error 'Latest upstream version matches the version given. Nothing to compare.' elsif versions.include?('_') && (compared_versions.size == (versions.size - 1)) warn 'Latest upstream version matches one of the versions given.' elsif compared_versions.size == 1 error 'Only one version specified. Specify at lease two versions.' end # This should match the final versions that has been compared @compared_versions = compared_versions compared_versions.each do |version| download_gems? ? get_package(gem_name, version) : get_specification(gem_name, version) end @report.set_header "Compared versions: #{@compared_versions}" comparators = [SpecComparator, FileListComparator, DependencyComparator, GemfileComparator] # Use different gem sources if specified with_sources @options[:sources] do comparators.each do |c| comparator = c.new cmp = (comparator.compares == :packages) ? gem_packages.values : gem_specs.values @report = comparator.compare(cmp, @report, @options) end end # Clean up FileUtils.rm_rf [:output] unless [:keep_all] end |
#print_results ⇒ Object
107 108 109 110 |
# File 'lib/rubygems/comparator.rb', line 107 def print_results info 'Printing results...' @report.print end |