Class: Spoom::Sorbet::Metrics
- Inherits:
-
T::Struct
- Object
- T::Struct
- Spoom::Sorbet::Metrics
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/sorbet/metrics.rb
Constant Summary collapse
- DEFAULT_PREFIX =
"ruby_typer.unknown.."
- SIGILS =
T.let(["ignore", "false", "true", "strict", "strong", "__STDLIB_INTERNAL"], T::Array[String])
Class Method Summary collapse
- .parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
- .parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object
- .parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #files_by_strictness ⇒ Object
- #files_count ⇒ Object
- #show(out = $stdout) ⇒ Object
- #to_s ⇒ Object
Class Method Details
.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
21 22 23 |
# File 'lib/spoom/sorbet/metrics.rb', line 21 def self.parse_file(path, prefix = DEFAULT_PREFIX) parse_string(File.read(path), prefix) end |
.parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/spoom/sorbet/metrics.rb', line 31 def self.parse_hash(obj, prefix = DEFAULT_PREFIX) Metrics.new( repo: obj.fetch("repo"), sha: obj.fetch("sha"), status: obj.fetch("status"), branch: obj.fetch("branch"), timestamp: obj.fetch("timestamp").to_i, uuid: obj.fetch("uuid"), metrics: obj["metrics"].each_with_object({}) do |metric, all| name = metric["name"] name = name.sub(prefix, '') all[name] = metric["value"].to_i end, ) end |
.parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object
26 27 28 |
# File 'lib/spoom/sorbet/metrics.rb', line 26 def self.parse_string(string, prefix = DEFAULT_PREFIX) parse_hash(JSON.parse(string), prefix) end |
Instance Method Details
#[](key) ⇒ Object
60 61 62 |
# File 'lib/spoom/sorbet/metrics.rb', line 60 def [](key) metrics[key] end |
#files_by_strictness ⇒ Object
48 49 50 51 52 |
# File 'lib/spoom/sorbet/metrics.rb', line 48 def files_by_strictness SIGILS.each_with_object({}) do |sigil, map| map[sigil] = metrics["types.input.files.sigil.#{sigil}"] end end |
#files_count ⇒ Object
55 56 57 |
# File 'lib/spoom/sorbet/metrics.rb', line 55 def files_count files_by_strictness.values.compact.sum end |
#show(out = $stdout) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/spoom/sorbet/metrics.rb', line 70 def show(out = $stdout) files = files_count out.puts "Sigils:" out.puts " files: #{files}" files_by_strictness.each do |sigil, value| next unless value out.puts " #{sigil}: #{value}#{percent(value, files)}" end out.puts "\nMethods:" m = metrics['types.input.methods.total'] s = metrics['types.sig.count'] out.puts " methods: #{m}" out.puts " signatures: #{s}#{percent(s, m)}" out.puts "\nSends:" t = metrics['types.input.sends.typed'] s = metrics['types.input.sends.total'] out.puts " sends: #{s}" out.puts " typed: #{t}#{percent(t, s)}" end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/spoom/sorbet/metrics.rb', line 65 def to_s "Metrics<#{repo}-#{}-#{status}>" end |