Sha256: 4813494d3804cd4e693c405d4e58b69a13d2f4dba51baa90d2c4c6d803480d48

Contents?: true

Size: 1.48 KB

Versions: 97

Compression:

Stored size: 1.48 KB

Contents

module CC
  module Analyzer
    class EngineOutput
      delegate :blank?, to: :raw_output

      def initialize(name, raw_output)
        @name = name
        @raw_output = raw_output
      end

      def issue?
        valid_with_type?("issue")
      end

      def measurement?
        valid_with_type?("measurement")
      end

      def as_issue
        Issue.new(name, raw_output)
      end

      def to_json
        if issue?
          as_issue.to_json
        elsif measurement?
          Measurement.new(name, raw_output).to_json
        end
      end

      def valid?
        valid_json? && validator && validator.valid?
      end

      def error
        if !valid_json?
          { message: "Invalid JSON", output: raw_output }
        elsif !validator.present?
          { message: "Unsupported document type", output: raw_output }
        else
          validator.error
        end
      end

      private

      attr_accessor :name, :raw_output

      def valid_json?
        parsed_output.present?
      end

      def valid_with_type?(type)
        parsed_output &&
          parsed_output["type"].present? &&
          parsed_output["type"].downcase == type
      end

      def parsed_output
        @parsed_output ||= JSON.parse(raw_output)
      rescue JSON::ParserError
        nil
      end

      def validator
        if issue?
          IssueValidator.new(parsed_output)
        elsif measurement?
          MeasurementValidator.new(parsed_output)
        end
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 2 rubygems

Version Path
codeclimate-0.96.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.95.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.94.1 lib/cc/analyzer/engine_output.rb
codeclimate-0.94.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.93.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.92.1 lib/cc/analyzer/engine_output.rb
codeclimate-0.92.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.91.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.90.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.89.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.88.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.5 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.4 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.3 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.2 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.1 lib/cc/analyzer/engine_output.rb
codeclimate-0.87.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.86.0 lib/cc/analyzer/engine_output.rb
codeclimate-0.85.29 lib/cc/analyzer/engine_output.rb
codeclimate-0.85.28 lib/cc/analyzer/engine_output.rb