Sha256: 113457620151865eb5e0e798759e4457a73e92f7b9962cb1e66079071bcf77cb

Contents?: true

Size: 1.48 KB

Versions: 54

Compression:

Stored size: 1.48 KB

Contents

require 'yaml'

require 'ruby_dep/travis/ruby_version'

module RubyDep
  class Travis
    def version_constraint(filename = '.travis.yml')
      yaml = YAML.load(IO.read(filename))
      versions = supported_versions(yaml)

      selected = versions_for_latest_major(versions)
      lowest = lowest_supported(selected)

      ["~> #{lowest[0..1].join('.')}", ">= #{lowest.join('.')}"]
    rescue RubyVersion::Error => ex
      abort("RubyDep Error: #{ex.message}")
    end

    private

    def versions_for_latest_major(versions)
      by_major = versions.map do |x|
        RubyVersion.new(x).segments[0..2]
      end.group_by(&:first)

      last_supported_major = by_major.keys.sort.last
      by_major[last_supported_major]
    end

    def lowest_supported(versions)
      selected = versions.sort.reverse!
      grouped_by_minor = selected.group_by { |x| x[1] }

      lowest_minor = lowest_minor_without_skipping(grouped_by_minor)
      grouped_by_minor[lowest_minor].sort.first
    end

    def failable(yaml)
      matrix = yaml.fetch('matrix', {})
      allowed = matrix.fetch('allow_failures', [])
      allowed.map(&:values).flatten
    end

    def supported_versions(yaml)
      yaml['rvm'] - failable(yaml)
    end

    def lowest_minor_without_skipping(grouped_by_minor)
      minors = grouped_by_minor.keys.flatten
      lowest = minors.shift
      current = lowest
      while (lower = minors.shift)
        (current -= 1) == lower ? lowest = lower : break
      end
      lowest
    end
  end
end

Version data entries

54 entries across 47 versions & 9 rubygems

Version Path
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/ruby_dep-1.5.0/lib/ruby_dep/travis.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/ruby_dep-1.5.0/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.5.0/lib/ruby_dep/travis.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.5.0/lib/ruby_dep/travis.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/ruby_dep-1.3.1/lib/ruby_dep/travis.rb