Sha256: fa4ae10f7c385953b8393ec0762bef208a15d9e46bffed90d84543861cc218dc

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

module CC
  module Analyzer
    class IssueValidator
      CHECKS = [
        IssueCategoryValidation,
        IssueCheckNamePresenceValidation,
        IssueDescriptionPresenceValidation,
        IssueLocationFormatValidation,
        IssueOtherLocationsFormatValidation,
        IssuePathExistenceValidation,
        IssuePathIsFileValidation,
        IssuePathPresenceValidation,
        IssueRelativePathValidation,
        IssueTypeValidation,
      ].freeze

      attr_reader :error

      def initialize(issue)
        @issue = issue
        validate
      end

      def validate
        return @valid unless @valid.nil?

        if issue && invalid_messages.any?
          @error = {
            message: "#{invalid_messages.join("; ")}: `#{issue}`.",
            issue: issue,
          }
          @valid = false
        else
          @valid = true
        end
      end
      alias valid? validate

      private

      attr_reader :issue

      def invalid_messages
        @invalid_messages ||= CHECKS.each_with_object([]) do |check, result|
          validator = check.new(issue)
          result << validator.message unless validator.valid?
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
codeclimate-0.34.1 lib/cc/analyzer/issue_validator.rb
codeclimate-0.34.0 lib/cc/analyzer/issue_validator.rb
codeclimate-0.33.0 lib/cc/analyzer/issue_validator.rb
codeclimate-0.32.1 lib/cc/analyzer/issue_validator.rb
codeclimate-0.32.0 lib/cc/analyzer/issue_validator.rb
codeclimate-0.32.0.rc1 lib/cc/analyzer/issue_validator.rb
codeclimate-0.31.1 lib/cc/analyzer/issue_validator.rb
codeclimate-0.31.0 lib/cc/analyzer/issue_validator.rb
codeclimate-0.30.1 lib/cc/analyzer/issue_validator.rb
codeclimate-0.30.0 lib/cc/analyzer/issue_validator.rb
codeclimate-0.29.0 lib/cc/analyzer/issue_validator.rb