<commit_before>module Bosh::Workspace
  class Credentials
    include Bosh::Cli::Validation
    include GitProtocolHelper
    attr_reader :raw_credentials

    def initialize(file)
      @raw_credentials = YAML.load_file file
    end

    def perform_validation(options = {})
      Schemas::Credentials.new.validate raw_credentials
    rescue Membrane::SchemaValidationError => e
      errors << e.message
    end

    def find_by_url(url)
      credentials[url]
    end

    def url_protocols
      raw_credentials.map { |c| [c['url'], git_protocol_from_url(c['url'])] }.to_h
    end

    private

    def credentials
      @credentials ||= begin
        raw_credentials.map { |c| [c.delete('url'), symbolize_keys(c)] }.to_h
      end
    end

    def symbolize_keys(hash)
      hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
    end
  end
end<commit_msg>Don't use to_h on Array (ruby > 2.1.0)<commit_after>module Bosh::Workspace
  class Credentials
    include Bosh::Cli::Validation
    include GitProtocolHelper
    attr_reader :raw_credentials

    def initialize(file)
      @raw_credentials = YAML.load_file file
    end

    def perform_validation(options = {})
      Schemas::Credentials.new.validate raw_credentials
    rescue Membrane::SchemaValidationError => e
      errors << e.message
    end

    def find_by_url(url)
      credentials[url]
    end

    def url_protocols
      Hash[raw_credentials.map { |c| [c['url'], git_protocol_from_url(c['url'])] }]
    end

    private

    def credentials
      @credentials ||= begin
        Hash[raw_credentials.map { |c| [c.delete('url'), symbolize_keys(c)] }]
      end
    end

    def symbolize_keys(hash)
      hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
    end
  end
end
{'fraction_non_alphanumeric': 0.11016467915956843, 'fraction_numerical': 0.0017035775127768314, 'mean_word_length': 2.986425339366516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '799031', 'n_tokens_mistral': 598, 'n_tokens_neox': 581, 'n_words': 125}