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.40.3 lib/cc/analyzer/issue.rb
codeclimate-0.40.2 lib/cc/analyzer/issue.rb
codeclimate-0.40.1 lib/cc/analyzer/issue.rb
codeclimate-0.40.0 lib/cc/analyzer/issue.rb
codeclimate-0.39.0 lib/cc/analyzer/issue.rb
codeclimate-0.38.1 lib/cc/analyzer/issue.rb
codeclimate-0.38.0 lib/cc/analyzer/issue.rb
codeclimate-0.37.0 lib/cc/analyzer/issue.rb
codeclimate-0.36.0 lib/cc/analyzer/issue.rb
codeclimate-0.35.2 lib/cc/analyzer/issue.rb
codeclimate-0.35.1 lib/cc/analyzer/issue.rb
codeclimate-0.35.0 lib/cc/analyzer/issue.rb
codeclimate-0.34.1 lib/cc/analyzer/issue.rb
codeclimate-0.34.0 lib/cc/analyzer/issue.rb
codeclimate-0.33.0 lib/cc/analyzer/issue.rb
codeclimate-0.32.1 lib/cc/analyzer/issue.rb
codeclimate-0.32.0 lib/cc/analyzer/issue.rb
codeclimate-0.32.0.rc1 lib/cc/analyzer/issue.rb
codeclimate-0.31.1 lib/cc/analyzer/issue.rb
codeclimate-0.31.0 lib/cc/analyzer/issue.rb