Sha256: ae469921e4c3708283669ce5a88c3441b5f0ba29ee89ba4f3590cc35c54f211b

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

module Steep
  module Services
    class StatsCalculator
      class SuccessStats < Struct.new(:target, :path, :typed_calls_count, :untyped_calls_count, :error_calls_count, keyword_init: true)
        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
      class ErrorStats < Struct.new(:target, :path, keyword_init: true)
        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
          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

22 entries across 22 versions & 1 rubygems

Version Path
steep-1.9.1 lib/steep/services/stats_calculator.rb
steep-1.9.0 lib/steep/services/stats_calculator.rb
steep-1.9.0.dev.2 lib/steep/services/stats_calculator.rb
steep-1.9.0.dev.1 lib/steep/services/stats_calculator.rb
steep-1.8.3 lib/steep/services/stats_calculator.rb
steep-1.8.2 lib/steep/services/stats_calculator.rb
steep-1.8.1 lib/steep/services/stats_calculator.rb
steep-1.8.0 lib/steep/services/stats_calculator.rb
steep-1.8.0.pre.2 lib/steep/services/stats_calculator.rb
steep-1.8.0.pre.1 lib/steep/services/stats_calculator.rb
steep-1.8.0.dev.2 lib/steep/services/stats_calculator.rb
steep-1.8.0.dev.1 lib/steep/services/stats_calculator.rb
steep-1.7.1 lib/steep/services/stats_calculator.rb
steep-1.7.0 lib/steep/services/stats_calculator.rb
steep-1.7.0.dev.3 lib/steep/services/stats_calculator.rb
steep-1.7.0.dev.2 lib/steep/services/stats_calculator.rb
steep-1.7.0.dev.1 lib/steep/services/stats_calculator.rb
steep-1.6.0 lib/steep/services/stats_calculator.rb
steep-1.6.0.pre.4 lib/steep/services/stats_calculator.rb
steep-1.6.0.pre.3 lib/steep/services/stats_calculator.rb