<commit_before>describe Hashing do
  describe 'when one of the ivars is an `Array` of hasherized objects' do
    class HashingCollectionOwner
      attr_reader :file, :commit, :annotations
      include Hasherize.new :file, :commit, :annotations

      loading ->(hash) { new hash[:file], hash[:commit], hash[:annotations] }

      def initialize(file, commit, annotations)
        @file, @commit, @annotations = file, commit, annotations
      end
    end

    class HashingCollectionMember
      attr_reader :annotation
      include Hasherize.new :annotation,
        to: ->(value) { "--#{value}" },
        from: ->(value) { "#{value}--" }

      loading ->(hash) { new hash[:annotation] }

      def initialize(annotation)
        @annotation = annotation
      end
    end

    describe '#to_h' do
      it 'calls #to_h for each array item when hashifying the object' do
        owner = HashingCollectionOwner.new 'README.md', 'cfe9aacbc02528b', [
          HashingCollectionMember.new('first'),
          HashingCollectionMember.new('second'),
        ]
        owner.to_h.must_be :==, {
          file: 'README.md',
          commit: 'cfe9aacbc02528b',
          annotations: [
            { annotation: '--first' },
            { annotation: '--second' },
          ],
          __hashing__: {
            types: {
              annotations: HashingCollectionMember
            }
          }
        }
      end<commit_msg>Note to self on feature api<commit_after>describe Hashing do
  describe 'when one of the ivars is an `Array` of hasherized objects' do
    class HashingCollectionOwner
      attr_reader :file, :commit, :annotations
      include Hasherize.new :file, :commit, :annotations

      loading ->(hash) { new hash[:file], hash[:commit], hash[:annotations] }

      def initialize(file, commit, annotations)
        @file, @commit, @annotations = file, commit, annotations
      end
    end

    class HashingCollectionMember
      attr_reader :annotation
      include Hasherize.new :annotation,
        to: ->(value) { "--#{value}" },
        from: ->(value) { "#{value}--" }

      loading ->(hash) { new hash[:annotation] }

      def initialize(annotation)
        @annotation = annotation
      end
    end

    it "since v0.1.0 we should be using the :collection option" do
      false.must_be :==, true
    end

    describe '#to_h' do
      it 'calls #to_h for each array item when hashifying the object' do
        owner = HashingCollectionOwner.new 'README.md', '<PASSWORD>', [
          HashingCollectionMember.new('first'),
          HashingCollectionMember.new('second'),
        ]
        owner.to_h.must_be :==, {
          file: 'README.md',
          commit: '<PASSWORD>',
          annotations: [
            { annotation: '--first' },
            { annotation: '--second' },
          ],
          __hashing__: {
            types: {
              annotations: HashingCollectionMember
            }
          }
        }
      end
{'fraction_non_alphanumeric': 0.11634162743779422, 'fraction_numerical': 0.005043712172158709, 'mean_word_length': 2.128286014721346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4093268', 'n_tokens_mistral': 854, 'n_tokens_neox': 826, 'n_words': 226}