<commit_before>module Mongoff
  class Record
    include Savable
    include Destroyable
    include Edi::Filler
    include Edi::Formatter
    include RecordsMethods
    include ActiveModel::ForbiddenAttributesProtection
    include Cenit::Liquidfier

    attr_reader :orm_model
    attr_reader :document
    attr_reader :fields

    def initialize(model, attributes = nil, new_record = true)
      @orm_model = model
      @document = BSON::Document.new
      unless (id_schema = model.property_schema(:_id)) && id_schema.key?('type')
        @document[:_id] ||= BSON::ObjectId.new
      end
      @fields = {}
      @new_record = new_record || false
      model.properties_schemas.each do |property, schema|
        if @document[property].nil? && !(value = schema['default']).nil?
          self[property] = value
        end
      end
      assign_attributes(attributes)
      Cenit::Utility.for_each_node_starting_at(self) { |record| record.instance_variable_set(:@new_record, false) } unless @new_record
      @changed = false
    end

    def attributes
      prepare_attributes
      document
    end

    def assign_attributes(attrs = nil)
      attrs ||= {}
      unless attrs.empty?
        attrs = sanitize_for_mass_assignment(attrs)<commit_msg>Fixing default mongoff records IDs<commit_after>module Mongoff
  class Record
    include Savable
    include Destroyable
    include Edi::Filler
    include Edi::Formatter
    include RecordsMethods
    include ActiveModel::ForbiddenAttributesProtection
    include Cenit::Liquidfier

    attr_reader :orm_model
    attr_reader :document
    attr_reader :fields

    def initialize(model, attributes = nil, new_record = true)
      @orm_model = model
      @document = BSON::Document.new
      @fields = {}
      @new_record = new_record || false
      model.properties_schemas.each do |property, schema|
        if @document[property].nil? && !(value = schema['default']).nil?
          self[property] = value
        end
      end
      assign_attributes(attributes)
      Cenit::Utility.for_each_node_starting_at(self) { |record| record.instance_variable_set(:@new_record, false) } unless @new_record
      unless (id_schema = model.property_schema(:_id)) && id_schema.key?('type')
        @document[:_id] ||= BSON::ObjectId.new
      end
      @changed = false
    end

    def attributes
      prepare_attributes
      document
    end

    def assign_attributes(attrs = nil)
      attrs ||= {}
      unless attrs.empty?
        attrs = sanitize_for_mass_assignment(attrs)
{'fraction_non_alphanumeric': 0.09309664694280079, 'fraction_numerical': 0.0, 'mean_word_length': 3.070626003210273, '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': '2932859', 'n_tokens_mistral': 740, 'n_tokens_neox': 733, 'n_words': 163}