<commit_before>require 'cocoapods-core'
require 'shellwords'
require 'timeout'

module Pod
  module TrunkApp
    class SpecificationWrapper
      def self.from_json(json)
        hash = JSON.parse(json)
        if hash.is_a?(Hash)
          new(Specification.from_hash(hash))
        end
      rescue JSON::ParserError
        # TODO: report error?
        nil
      end

      def initialize(specification)
        @specification = specification
      end

      def name
        @specification.name
      end

      def version
        @specification.version.to_s
      end

      def to_s
        @specification.to_s
      end

      def to_json(*a)
        @specification.to_json(*a)
      end

      def to_pretty_json(*a)
        @specification.to_pretty_json(*a)
      end

      def valid?
        linter.lint
      end

      def validation_errors
        results = {}
        results['warnings'] = remove_prefixes(linter.warnings) unless linter.warnings.empty?
        results['errors']   = remove_prefixes(linter.errors)   unless linter.errors.empty?
        results
      end

      def publicly_accessible?
        return validate_http if @specification.source[:http]
        return validate_git if @specification.source[:git]
        true
      end

      def validate_http
       wrap_timeout Proc.new({ Pod::HTTP.validate_url @specification.source[:http] })
      end

      def validate_git
        wrap_timeout Proc.new({ system('git', 'ls-remote', @specification.source[:git], 'HEAD') })
      end

      private

      def wrap_timeout proc
        begin
          Timeout.timeout(5) do
           return proc.call
          end
        rescue Timeout::Error
          return false
        end<commit_msg>[rubocop] Appease the rubocop<commit_after>require 'cocoapods-core'
require 'shellwords'
require 'timeout'

module Pod
  module TrunkApp
    class SpecificationWrapper
      def self.from_json(json)
        hash = JSON.parse(json)
        if hash.is_a?(Hash)
          new(Specification.from_hash(hash))
        end
      rescue JSON::ParserError
        # TODO: report error?
        nil
      end

      def initialize(specification)
        @specification = specification
      end

      def name
        @specification.name
      end

      def version
        @specification.version.to_s
      end

      def to_s
        @specification.to_s
      end

      def to_json(*a)
        @specification.to_json(*a)
      end

      def to_pretty_json(*a)
        @specification.to_pretty_json(*a)
      end

      def valid?
        linter.lint
      end

      def validation_errors
        results = {}
        results['warnings'] = remove_prefixes(linter.warnings) unless linter.warnings.empty?
        results['errors']   = remove_prefixes(linter.errors)   unless linter.errors.empty?
        results
      end

      def publicly_accessible?
        return validate_http if @specification.source[:http]
        return validate_git if @specification.source[:git]
        true
      end

      def validate_http
        wrap_timeout proc { Pod::HTTP.validate_url(@specification.source[:http]) }
      end

      def validate_git
        wrap_timeout proc { system('git', 'ls-remote', @specification.source[:git], 'HEAD') }
      end

      private

      def wrap_timeout(closure)
        Timeout.timeout(5) do
          return closure.call
        end
      rescue Timeout::Error
          return false
{'fraction_non_alphanumeric': 0.07983682983682984, 'fraction_numerical': 0.0005827505827505828, 'mean_word_length': 2.038053097345133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869135', 'n_tokens_mistral': 1003, 'n_tokens_neox': 967, 'n_words': 222}