module Spoom::Sorbet

Constants

BIN_PATH
CONFIG_PATH
GEM_PATH

Public Class Methods

srb(*arg, path: '.', capture_err: false, sorbet_bin: nil) click to toggle source
# File lib/spoom/sorbet.rb, line 29
def srb(*arg, path: '.', capture_err: false, sorbet_bin: nil)
  if sorbet_bin
    arg.prepend(sorbet_bin)
  else
    arg.prepend("bundle", "exec", "srb")
  end
  T.unsafe(Spoom).exec(*arg, path: path, capture_err: capture_err)
end
srb_files(config, path: '.') click to toggle source
# File lib/spoom/sorbet.rb, line 53
def srb_files(config, path: '.')
  regs = config.ignore.map { |string| Regexp.new(Regexp.escape(string)) }
  exts = config.allowed_extensions.empty? ? ['.rb', '.rbi'] : config.allowed_extensions
  Dir.glob((Pathname.new(path) / "**/*{#{exts.join(',')}}").to_s).reject do |f|
    regs.any? { |re| re.match?(f) }
  end.sort
end
srb_metrics(*arg, path: '.', capture_err: false, sorbet_bin: nil) click to toggle source
# File lib/spoom/sorbet.rb, line 90
def srb_metrics(*arg, path: '.', capture_err: false, sorbet_bin: nil)
  metrics_file = "metrics.tmp"
  metrics_path = "#{path}/#{metrics_file}"
  T.unsafe(self).srb_tc(
    "--metrics-file",
    metrics_file,
    *arg,
    path: path,
    capture_err: capture_err,
    sorbet_bin: sorbet_bin
  )
  if File.exist?(metrics_path)
    metrics = Spoom::Sorbet::MetricsParser.parse_file(metrics_path)
    File.delete(metrics_path)
    return metrics
  end
  nil
end
srb_tc(*arg, path: '.', capture_err: false, sorbet_bin: nil) click to toggle source
# File lib/spoom/sorbet.rb, line 46
def srb_tc(*arg, path: '.', capture_err: false, sorbet_bin: nil)
  arg.prepend("tc") unless sorbet_bin
  T.unsafe(self).srb(*arg, path: path, capture_err: capture_err, sorbet_bin: sorbet_bin)
end
srb_version(*arg, path: '.', capture_err: false, sorbet_bin: nil) click to toggle source
# File lib/spoom/sorbet.rb, line 69
def srb_version(*arg, path: '.', capture_err: false, sorbet_bin: nil)
  out, res = T.unsafe(self).srb_tc(
    "--no-config",
    "--version",
    *arg,
    path: path,
    capture_err: capture_err,
    sorbet_bin: sorbet_bin
  )
  return nil unless res
  out.split(" ")[2]
end
version_from_gemfile_lock(gem: 'sorbet', path: '.') click to toggle source
# File lib/spoom/sorbet.rb, line 113
def version_from_gemfile_lock(gem: 'sorbet', path: '.')
  gemfile_path = "#{path}/Gemfile.lock"
  return nil unless File.exist?(gemfile_path)
  content = File.read(gemfile_path).match(/^    #{gem} \(.*(\d+\.\d+\.\d+).*\)/)
  return nil unless content
  content[1]
end