<commit_before>module Toy
  module Mongo
    module PartialUpdating
      extend ActiveSupport::Concern

      included do
        class_attribute :partial_updates

        self.partial_updates = false
      end

      # Very basic method for determining what has changed locally
      # so we can just update changes instead of entire document
      #
      # Does not work with complex objects (array, hash, set, etc.)
      # as it does not attempt to determine what has changed in them,
      # just whether or not they have changed at all.
      def persistable_changes
        attrs = {}
        pattrs = persisted_attributes
        changed.each do |key|
          attribute = self.class.attributes[key.to_s]
          next if attribute.virtual?
          attrs[attribute.persisted_name] = pattrs[attribute.persisted_name]
        end
        attrs
      end

      def persist
        if partial_updates?
          updates = persistable_changes
          if new_record? || (persisted? && updates.present?)
            adapter.write id, updates
          end
        else
          super
        end
      end

      def atomic_update(update, opts={})
        options  = {}
        criteria = {'_id' => id}
        criteria.update(opts[:criteria]) if opts[:criteria]
        options[:safe] = opts.key?(:safe) ? opts[:safe] : adapter.options[:safe]

        run_callbacks(:save) do
          run_callbacks(:update) do
            adapter.client.update(criteria, update, options)
          end
        end
      end
    end
  end
end<commit_msg>String to symbol.<commit_after>module Toy
  module Mongo
    module PartialUpdating
      extend ActiveSupport::Concern

      included do
        class_attribute :partial_updates

        self.partial_updates = false
      end

      # Very basic method for determining what has changed locally
      # so we can just update changes instead of entire document
      #
      # Does not work with complex objects (array, hash, set, etc.)
      # as it does not attempt to determine what has changed in them,
      # just whether or not they have changed at all.
      def persistable_changes
        attrs = {}
        pattrs = persisted_attributes
        changed.each do |key|
          attribute = self.class.attributes[key.to_s]
          next if attribute.virtual?
          attrs[attribute.persisted_name] = pattrs[attribute.persisted_name]
        end
        attrs
      end

      def persist
        if partial_updates?
          updates = persistable_changes
          if new_record? || (persisted? && updates.present?)
            adapter.write id, updates
          end
        else
          super
        end
      end

      def atomic_update(update, opts={})
        options  = {}
        criteria = {:_id => id}
        criteria.update(opts[:criteria]) if opts[:criteria]
        options[:safe] = opts.key?(:safe) ? opts[:safe] : adapter.options[:safe]

        run_callbacks(:save) do
          run_callbacks(:update) do
            adapter.client.update(criteria, update, options)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07283274250725105, 'fraction_numerical': 0.0, 'mean_word_length': 1.9903660886319845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5429293', 'n_tokens_mistral': 826, 'n_tokens_neox': 807, 'n_words': 257}