Sha256: 577e8ef8c2c903241152b96d0f38becbafedf4e53e871e6a5ce78b5db7a0f524

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

require 'rubygems/comparator/base'

class Gem::Comparator

  ##
  # Gem::Comparator::SpecComparator can
  # compare values from the gem verions specs

  class SpecComparator < Gem::Comparator::Base

    ##
    # Compare common fields in spec

    def compare(specs, report, options = {})
      info 'Checking spec parameters...'
      p = options[:param]
      b = options[:brief]

      filter_params(SPEC_PARAMS, p, b).each do |param|
        values = values_from_specs(param, specs)

        if same_values?(values) && options[:log_all]
          v = value(values[0])
          report[param].section do
            set_header "#{self.same} #{param}:"
            puts v
          end
        elsif !same_values?(values)
          report[param].set_header "#{different} #{param}:"
          values.each_with_index do |value, index|
            report[param] << \
              "#{Rainbow(specs[index].version).cyan}: #{value}"
          end
        end
      end
      report
    end

    private

      def value(value)
        case value
        when Gem::Requirement
          unless value.requirements.empty?
            r = value.requirements[0]
            "#{r[0]} #{r[1].version} "
          else
            '[]'
          end
        when Gem::Platform
          value.to_s
        when String
          return value unless value.empty?
          ''
        else
          value.inspect
        end
      end

      def same_values?(values)
        values.count(values[0]) == values.size
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gem-compare-1.2.1 lib/rubygems/comparator/spec_comparator.rb
gem-compare-1.2.0 lib/rubygems/comparator/spec_comparator.rb
gem-compare-1.1.0 lib/rubygems/comparator/spec_comparator.rb
gem-compare-1.0.0 lib/rubygems/comparator/spec_comparator.rb
gem-compare-0.0.7 lib/rubygems/comparator/spec_comparator.rb
gem-compare-0.0.6 lib/rubygems/comparator/spec_comparator.rb