Module: Spoom::Sorbet

Extended by:
T::Sig
Defined in:
lib/spoom/sorbet.rb,
lib/spoom/sorbet/config.rb,
lib/spoom/sorbet/errors.rb,
lib/spoom/sorbet/metrics.rb

Defined Under Namespace

Modules: Errors Classes: Config, Metrics

Class Method Summary collapse

Class Method Details

.srb(*arg, path: '.', capture_err: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spoom/sorbet.rb', line 16

def self.srb(*arg, path: '.', capture_err: false)
  opts = {}
  opts[:chdir] = path
  out = T.let("", T.nilable(String))
  res = T.let(false, T::Boolean)
  if capture_err
    Open3.popen2e(["bundle", "exec", "srb", *arg].join(" "), opts) do |_, o, t|
      out = o.read
      res = T.cast(t.value, Process::Status).success?
    end
  else
    Open3.popen2(["bundle", "exec", "srb", *arg].join(" "), opts) do |_, o, t|
      out = o.read
      res = T.cast(t.value, Process::Status).success?
    end
  end
  [out || "", res]
end

.srb_files(config, path: '.') ⇒ Object



42
43
44
45
46
47
48
# File 'lib/spoom/sorbet.rb', line 42

def self.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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spoom/sorbet.rb', line 58

def self.srb_metrics(*arg, path: '.', capture_err: false)
  metrics_file = "metrics.tmp"
  metrics_path = "#{path}/#{metrics_file}"
  srb_tc(*T.unsafe(["--metrics-file=#{metrics_file}", *arg]), path: path, capture_err: capture_err)
  if File.exist?(metrics_path)
    metrics = Spoom::Sorbet::Metrics.parse_file(metrics_path)
    File.delete(metrics_path)
    return metrics
  end
  nil
end

.srb_tc(*arg, path: '.', capture_err: false) ⇒ Object



36
37
38
# File 'lib/spoom/sorbet.rb', line 36

def self.srb_tc(*arg, path: '.', capture_err: false)
  srb(*T.unsafe(["tc", *arg]), path: path, capture_err: capture_err)
end

.srb_version(*arg, path: '.', capture_err: false) ⇒ Object



51
52
53
54
55
# File 'lib/spoom/sorbet.rb', line 51

def self.srb_version(*arg, path: '.', capture_err: false)
  out, res = srb(*T.unsafe(["--version", *arg]), path: path, capture_err: capture_err)
  return nil unless res
  out.split(" ")[2]
end