lib/spoom/sorbet.rb in spoom-1.0.4 vs lib/spoom/sorbet.rb in spoom-1.0.5
- old
+ new
@@ -3,10 +3,11 @@
require "spoom/sorbet/config"
require "spoom/sorbet/errors"
require "spoom/sorbet/lsp"
require "spoom/sorbet/metrics"
+require "spoom/sorbet/sigils"
require "open3"
module Spoom
module Sorbet
@@ -52,19 +53,31 @@
out, res = srb(*T.unsafe(["--version", *arg]), path: path, capture_err: capture_err)
return nil unless res
out.split(" ")[2]
end
- sig { params(arg: String, path: String, capture_err: T::Boolean).returns(T.nilable(Metrics)) }
+ sig { params(arg: String, path: String, capture_err: T::Boolean).returns(T.nilable(T::Hash[String, Integer])) }
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)
+ metrics = Spoom::Sorbet::MetricsParser.parse_file(metrics_path)
File.delete(metrics_path)
return metrics
end
nil
+ end
+
+ # Get `gem` version from the `Gemfile.lock` content
+ #
+ # Returns `nil` if `gem` cannot be found in the Gemfile.
+ sig { params(gem: String, path: String).returns(T.nilable(String)) }
+ def self.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
end
end