<commit_before>module CapsuleCRM
  class Serializer
    attr_reader :object, :options

    def initialize(options = {})
      @options = options
    end

    def serialize(object)
      @object = object
      @serialized ||=
        if include_root?
          serialize_with_root
        else
          serialize_without_root
        end
    end

    def self.serialize_collection(klass, collection)
      collection = collection.map do |item|
        options = klass.serializable_options
        options.include_root = false
        ::CapsuleCRM::Serializer.new(options).serialize(item)
      end
      { klass.serializable_options.root => collection }
    end

    def serialize_with_root
      { root => build_attributes_hash }.stringify_keys<commit_msg>dup serializable options in serializer in order to avoid bugs<commit_after>module CapsuleCRM
  class Serializer
    attr_reader :object, :options

    def initialize(options = {})
      @options = options
    end

    def serialize(object)
      @object = object
      @serialized ||=
        if include_root?
          serialize_with_root
        else
          serialize_without_root
        end
    end

    def self.serialize_collection(klass, collection)
      collection = collection.map do |item|
        options = klass.serializable_options.dup
        options.include_root = false
        ::CapsuleCRM::Serializer.new(options).serialize(item)
      end
      { klass.serializable_options.root => collection }
    end

    def serialize_with_root
      { root => build_attributes_hash }.stringify_keys
{'fraction_non_alphanumeric': 0.07088122605363985, 'fraction_numerical': 0.0, 'mean_word_length': 2.569476082004556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3718772', 'n_tokens_mistral': 432, 'n_tokens_neox': 427, 'n_words': 98}