Sha256: 25d60dd47602fd90dbfd2ab66032bdde52e7658422e91b8414140979e24c63e2

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 KB

Contents

# typed: strict
# frozen_string_literal: true

require_relative "sigils"

module Spoom
  module Sorbet
    module MetricsParser
      DEFAULT_PREFIX = "ruby_typer.unknown.."

      class << self
        extend T::Sig

        sig { params(path: String, prefix: String).returns(T::Hash[String, Integer]) }
        def parse_file(path, prefix = DEFAULT_PREFIX)
          parse_string(File.read(path), prefix)
        end

        sig { params(string: String, prefix: String).returns(T::Hash[String, Integer]) }
        def parse_string(string, prefix = DEFAULT_PREFIX)
          parse_hash(JSON.parse(string), prefix)
        end

        sig { params(obj: T::Hash[String, T.untyped], prefix: String).returns(T::Hash[String, Integer]) }
        def parse_hash(obj, prefix = DEFAULT_PREFIX)
          obj["metrics"].each_with_object(Hash.new(0)) do |metric, metrics|
            name = metric["name"]
            name = name.sub(prefix, "")
            metrics[name] = metric["value"] || 0
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
spoom-1.4.2 lib/spoom/sorbet/metrics.rb
spoom-1.4.1 lib/spoom/sorbet/metrics.rb
spoom-1.4.0 lib/spoom/sorbet/metrics.rb
spoom-1.3.3 lib/spoom/sorbet/metrics.rb
spoom-1.3.2 lib/spoom/sorbet/metrics.rb
spoom-1.3.1 lib/spoom/sorbet/metrics.rb
spoom-1.3.0 lib/spoom/sorbet/metrics.rb
spoom-1.2.4 lib/spoom/sorbet/metrics.rb
spoom-1.2.3 lib/spoom/sorbet/metrics.rb
spoom-1.2.2 lib/spoom/sorbet/metrics.rb
spoom-1.2.1 lib/spoom/sorbet/metrics.rb
spoom-1.2.0 lib/spoom/sorbet/metrics.rb
spoom-1.1.16 lib/spoom/sorbet/metrics.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/spoom-1.1.15/lib/spoom/sorbet/metrics.rb
spoom-1.1.15 lib/spoom/sorbet/metrics.rb
spoom-1.1.14 lib/spoom/sorbet/metrics.rb
spoom-1.1.13 lib/spoom/sorbet/metrics.rb
spoom-1.1.12 lib/spoom/sorbet/metrics.rb