Sha256: 8e83687f10e677162118251cf4bbb6c0271915d606df0f29efd92312be8c0705

Contents?: true

Size: 1.8 KB

Versions: 18

Compression:

Stored size: 1.8 KB

Contents

module Steep
  module Services
    class StatsCalculator
      SuccessStats = Struct.new(:target, :path, :typed_calls_count, :untyped_calls_count, :error_calls_count, keyword_init: true) do
        def as_json
          {
            type: "success",
            target: target.name.to_s,
            path: path.to_s,
            typed_calls: typed_calls_count,
            untyped_calls: untyped_calls_count,
            error_calls: error_calls_count,
            total_calls: typed_calls_count + untyped_calls_count + error_calls_count
          }
        end
      end
      ErrorStats = Struct.new(:target, :path, keyword_init: true) do
        def as_json
          {
            type: "error",
            target: target.name.to_s,
            path: path.to_s
          }
        end
      end

      attr_reader :service

      def initialize(service:)
        @service = service
      end

      def project
        service.project
      end

      def calc_stats(target, file:)
        if typing = file.typing
          typed = 0
          untyped = 0
          errors = 0
          total = 0
          typing.method_calls.each_value do |call|
            case call
            when TypeInference::MethodCall::Typed
              typed += 1
            when TypeInference::MethodCall::Untyped
              untyped += 1
            when TypeInference::MethodCall::Error, TypeInference::MethodCall::NoMethodError
              errors += 1
            else
              raise
            end
          end

          SuccessStats.new(
            target: target,
            path: file.path,
            typed_calls_count: typed,
            untyped_calls_count: untyped,
            error_calls_count: errors
          )
        else
          ErrorStats.new(target: target, path: file.path)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
steep-1.0.0 lib/steep/services/stats_calculator.rb
steep-0.52.2 lib/steep/services/stats_calculator.rb
steep-0.52.1 lib/steep/services/stats_calculator.rb
steep-0.52.0 lib/steep/services/stats_calculator.rb
steep-0.51.0 lib/steep/services/stats_calculator.rb
steep-0.50.0 lib/steep/services/stats_calculator.rb
steep-0.49.1 lib/steep/services/stats_calculator.rb
steep-0.49.0 lib/steep/services/stats_calculator.rb
steep-0.48.0 lib/steep/services/stats_calculator.rb
steep-0.47.1 lib/steep/services/stats_calculator.rb
steep-0.47.0 lib/steep/services/stats_calculator.rb
steep-0.46.0 lib/steep/services/stats_calculator.rb
steep-0.45.0 lib/steep/services/stats_calculator.rb
steep-0.44.1 lib/steep/services/stats_calculator.rb
steep-0.44.0 lib/steep/services/stats_calculator.rb
steep-0.43.1 lib/steep/services/stats_calculator.rb
steep-0.43.0 lib/steep/services/stats_calculator.rb
steep-0.42.0 lib/steep/services/stats_calculator.rb