Sha256: 7cb18eb2fe904222898d5bbf41062fc592694a53ff49e587e40a903039791a77

Contents?: true

Size: 1.08 KB

Versions: 38

Compression:

Stored size: 1.08 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

      private

      attr_reader :output

      def default_fingerprint
        digest = Digest::MD5.new
        digest << path
        digest << "|"
        digest << check_name.to_s
        digest.to_s
      end

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

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
codeclimate-0.26.0 lib/cc/analyzer/issue.rb
codeclimate-0.25.1 lib/cc/analyzer/issue.rb
codeclimate-0.25.0 lib/cc/analyzer/issue.rb
codeclimate-0.24.3 lib/cc/analyzer/issue.rb
codeclimate-0.24.2 lib/cc/analyzer/issue.rb
codeclimate-0.24.1 lib/cc/analyzer/issue.rb
codeclimate-0.24.0 lib/cc/analyzer/issue.rb
codeclimate-0.23.0 lib/cc/analyzer/issue.rb
codeclimate-0.22.3 lib/cc/analyzer/issue.rb
codeclimate-0.22.2 lib/cc/analyzer/issue.rb
codeclimate-0.22.1 lib/cc/analyzer/issue.rb
codeclimate-0.22.0 lib/cc/analyzer/issue.rb
codeclimate-0.21.4 lib/cc/analyzer/issue.rb
codeclimate-0.21.3 lib/cc/analyzer/issue.rb
codeclimate-0.21.2 lib/cc/analyzer/issue.rb
codeclimate-0.21.1 lib/cc/analyzer/issue.rb
codeclimate-0.21.0 lib/cc/analyzer/issue.rb
codeclimate-0.20.2 lib/cc/analyzer/issue.rb
codeclimate-0.20.1 lib/cc/analyzer/issue.rb
codeclimate-0.20.0 lib/cc/analyzer/issue.rb