class Gemika::Matrix

Constants

COLOR_FAILURE
COLOR_HEAD
COLOR_RESET
COLOR_SUCCESS
COLOR_WARNING

Attributes

current_ruby[R]
rows[R]

Public Class Methods

from_ci_config() click to toggle source

Builds a {Matrix} from a `.travis.yml` file, or falls back to a Github Action .yml file

@param [Hash] options @option options [String] Path to the `.travis.yml` file.

# File lib/gemika/matrix.rb, line 104
def self.from_ci_config
  travis_location = '.travis.yml'
  workflow_location = '.github/workflows/test.yml'
  if File.exists?(travis_location)
    from_travis_yml(:path => travis_location)
  elsif File.exists?(workflow_location)
    from_github_actions_yml(:path => workflow_location)
  else
    raise MissingMatrixDefinition, "expected either a #{travis_location} or a #{workflow_location}"
  end
end
from_github_actions_yml(options = {}) click to toggle source

Builds a {Matrix} from the given Github Action workflow definition

@param [Hash] options @option options [String] Path to the `.yml` file.

# File lib/gemika/matrix.rb, line 133
def self.from_github_actions_yml(options = {})
  rows = GithubActionsConfig.load_rows(options)
  new(options.merge(:rows => rows))
end
from_travis_yml(options = {}) click to toggle source

Builds a {Matrix} from the given `.travis.yml` file.

@param [Hash] options @option options [String] Path to the `.travis.yml` file.

# File lib/gemika/matrix.rb, line 122
def self.from_travis_yml(options = {})
  rows = TravisConfig.load_rows(options)
  new(options.merge(:rows => rows))
end
generate_github_actions_workflow(options= {}) click to toggle source
# File lib/gemika/matrix.rb, line 140
def self.generate_github_actions_workflow(options= {})
  require 'gemika/github_actions_generator'
  rows = TravisConfig.load_rows(options)
  GithubActionsGenerator.new(bundler_version: Bundler::VERSION).generate(rows)
end
new(options) click to toggle source
# File lib/gemika/matrix.rb, line 56
def initialize(options)
  @rows = options.fetch(:rows)
  @silent = options.fetch(:silent, false)
  @io = options.fetch(:io, STDOUT)
  @color = options.fetch(:color, true)
  validate = options.fetch(:validate, true)
  @rows.each(&:validate!) if validate
  @results = Env.new_ordered_hash
  @compatible_count = 0
  @all_passed = nil
  @current_ruby = options.fetch(:current_ruby, RUBY_VERSION)
end

Public Instance Methods

each(&block) click to toggle source

Runs the given `block` for each matrix row that is compatible with the current Ruby.

The row's gemfile will be set as an environment variable, so Bundler will use that gemfile if you shell out in `block`.

At the end it will print a summary of which rows have passed, failed or were skipped (due to incompatible Ruby version).

# File lib/gemika/matrix.rb, line 76
def each(&block)
  @all_passed = true
  rows.each do |row|
    gemfile = row.gemfile
    if row.compatible_with_ruby?(current_ruby)
      @compatible_count += 1
      print_title gemfile
      gemfile_passed = Env.with_gemfile(gemfile, row, &block)
      @all_passed &= gemfile_passed
      if gemfile_passed
        @results[row] = tint('Success', COLOR_SUCCESS)
      else
        @results[row] = tint('Failed', COLOR_FAILURE)
      end
    else
      @results[row] = tint("Skipped", COLOR_WARNING)
    end
  end
  print_summary
end

Private Instance Methods

print_summary() click to toggle source
print_title(title) click to toggle source
puts(*args) click to toggle source
# File lib/gemika/matrix.rb, line 148
def puts(*args)
  unless @silent
    @io.puts(*args)
  end
end
tint(message, color) click to toggle source
# File lib/gemika/matrix.rb, line 154
def tint(message, color)
  if @color
    color + message + COLOR_RESET
  else
    message
  end
end