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
Class Method Summary
collapse
-
.srb(*arg, path: '.', capture_err: false, sorbet_bin: nil) ⇒ Object
-
.srb_files(config, path: '.') ⇒ Object
-
.srb_metrics(*arg, path: '.', capture_err: false, sorbet_bin: nil) ⇒ Object
-
.srb_tc(*arg, path: '.', capture_err: false, sorbet_bin: nil) ⇒ Object
-
.srb_version(*arg, path: '.', capture_err: false, sorbet_bin: nil) ⇒ Object
-
.version_from_gemfile_lock(gem: 'sorbet', path: '.') ⇒ Object
Class Method Details
.srb(*arg, path: '.', capture_err: false, sorbet_bin: nil) ⇒ Object
29
30
31
32
33
34
35
36
|
# 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: '.') ⇒ Object
53
54
55
56
57
58
59
|
# 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) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# 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) ⇒ Object
46
47
48
49
|
# 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) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# 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: '.') ⇒ Object
113
114
115
116
117
118
119
|
# 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
|