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/sigils.rb,
lib/spoom/sorbet/metrics.rb

Defined Under Namespace

Modules: Errors, MetricsParser, Sigils Classes: Config

Constant Summary collapse

CONFIG_PATH =
"sorbet/config"
GEM_PATH =
Gem::Specification.find_by_name("sorbet-static").full_gem_path
BIN_PATH =
(Pathname.new(GEM_PATH) / "libexec" / "sorbet").to_s
SEGFAULT_CODE =
139

Class Method Summary collapse

Class Method Details

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


31
32
33
34
35
36
37
38
# File 'lib/spoom/sorbet.rb', line 31

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: '.') ⇒ Object


55
56
57
58
59
60
61
# File 'lib/spoom/sorbet.rb', line 55

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) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/spoom/sorbet.rb', line 92

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) ⇒ Object


48
49
50
51
# File 'lib/spoom/sorbet.rb', line 48

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) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/spoom/sorbet.rb', line 71

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: '.') ⇒ Object


115
116
117
118
119
120
121
# File 'lib/spoom/sorbet.rb', line 115

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