-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathspec_comparator.rb
More file actions
66 lines (55 loc) · 1.51 KB
/
spec_comparator.rb
File metadata and controls
66 lines (55 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
60
61
62
63
64
65
66
# frozen_string_literal: true
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