Class: TravisCheckRubies::TravisYml

Inherits:
Object
  • Object
show all
Defined in:
lib/travis_check_rubies/travis_yml.rb

Defined Under Namespace

Classes: Suggestion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: '.travis.yml', options: {}) ⇒ TravisYml

Returns a new instance of TravisYml.



13
14
15
16
# File 'lib/travis_check_rubies/travis_yml.rb', line 13

def initialize(path: '.travis.yml', options: {})
  @path = FSPath(path)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/travis_check_rubies/travis_yml.rb', line 11

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/travis_check_rubies/travis_yml.rb', line 11

def path
  @path
end

Instance Method Details

#suggestObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/travis_check_rubies/travis_yml.rb', line 65

def suggest
  puts warnings

  suggestions.group_by(&:section).each do |section, section_suggestions|
    puts "#{section}:"
    section_suggestions.each do |suggestion|
      puts "  #{suggestion.from} -> #{suggestion.choices.join(', ')}"
    end
  end

  warnings.empty? && suggestions.empty?
end

#suggestionsObject



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
# File 'lib/travis_check_rubies/travis_yml.rb', line 38

def suggestions
  return @suggestions if @suggestions

  @suggestions = []

  updates = Version.updates(rvm_versions, options)
  rvm_versions.each do |version|
    next unless (suggestions = updates[version])
    @suggestions << Suggestion.new('rvm', version, suggestions)
  end

  {
    'allow_failures' => allow_failures_versions,
    'exclude' => exclude_versions,
    'include' => include_versions,
  }.each do |section, versions|
    versions.each do |version|
      next unless (suggestions = Version.update(version, options))
      next if suggestions.include?(version)
      to = section == 'include' && !options[:conservative] ? suggestions.last : suggestions.first
      @suggestions << Suggestion.new(section, version, suggestions, to)
    end
  end

  @suggestions
end

#updateObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/travis_check_rubies/travis_yml.rb', line 78

def update
  unless warnings.empty?
    puts warnings

    return false
  end

  unless YAML.load(updated_content) == expected_object
    puts updated_content

    return false
  end

  FSPath.temp_file(path.basename, path.dirname) do |f|
    f.write(updated_content)
    f.path.rename(path)
  end

  true
end

#warningsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/travis_check_rubies/travis_yml.rb', line 18

def warnings
  return @warnings if @warnings

  @warnings = []

  rvm_versions.group_by(&:itself).select{ |_, versions| versions.count > 1 }.each do |version, _|
    @warnings << "#{version} in rvm is repeating"
  end

  (allow_failures_versions - rvm_versions - include_versions).each do |version|
    @warnings << "#{version} in matrix.allow_failures is not in rvm or include list"
  end

  (exclude_versions - rvm_versions).each do |version|
    @warnings << "#{version} in matrix.exclude is not in rvm list"
  end

  @warnings
end