Sha256: 6507dab479eda58e9ce141b5e2468e42e9d967a5b78bad7fbe700efc5572977f

Contents?: true

Size: 1 KB

Versions: 46

Compression:

Stored size: 1 KB

Contents

module CC
  module Analyzer
    class Issue
      SPEC_ISSUE_ATTRIBUTES = %w[
        categories
        check_name
        content
        description
        location
        other_locations
        remediation_points
        severity
        type
      ]

      def initialize(output)
        @output = output
      end

      def as_json(*)
        parsed_output.reverse_merge!(
          "fingerprint" => fingerprint,
        )
      end

      def fingerprint
        parsed_output.fetch("fingerprint") { default_fingerprint }
      end

      # Allow access to hash keys as methods
      SPEC_ISSUE_ATTRIBUTES.each do |key|
        define_method(key) do
          parsed_output[key]
        end
      end

      def path
        parsed_output.fetch("location", {}).fetch("path", "")
      end

      private

      attr_reader :output

      def default_fingerprint
        SourceFingerprint.new(self).compute
      end

      def parsed_output
        @parsed_output ||= JSON.parse(output)
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
codeclimate-0.30.1 lib/cc/analyzer/issue.rb
codeclimate-0.30.0 lib/cc/analyzer/issue.rb
codeclimate-0.29.0 lib/cc/analyzer/issue.rb
codeclimate-0.28.0 lib/cc/analyzer/issue.rb
codeclimate-0.27.2 lib/cc/analyzer/issue.rb
codeclimate-0.27.1 lib/cc/analyzer/issue.rb