jonatas/fast

View on GitHub
bin/fast-experiment

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))

require 'fast'
require 'fast/experiment'
require 'coderay'

arguments = ARGV

experiment_files = Fast.ruby_files_from(File.expand_path('../experiments', __dir__))
experiment_files.each(&method(:require))
experiments = []

if arguments.any?
  experiments << arguments.shift while arguments.any? && !(File.exist?(arguments.first) || Dir.exist?(arguments.first))
  experiments.map! { |name| Fast.experiments[name] }
else
  experiments = Fast.experiments.values
end

if arguments.any?
  ruby_files = arguments.all? { |e| File.exist?(e) && e.end_with?('.rb') }
  experiments.each do |experiment|
    if ruby_files
      experiment.files = arguments
    else
      experiment.lookup arguments
    end
  end
end
experiments.each(&:run)