<commit_before>module Dao
  module Gateway
    module ActiveRecord
      class Base < Dao::Gateway::Base
        include ActiveSupport::Rescuable

        def initialize(source, transformer)
          super
          @black_list_attributes += source_relations
        end

        def save!(domain, attributes)
          record = export(domain, record(domain.id))
          record.assign_attributes(attributes)
          record.save!
          domain.attributes = import(record, domain.initialized_with).attributes
          domain
        rescue ::ActiveRecord::RecordInvalid
          raise Dao::Gateway::InvalidRecord.new(record.errors.to_hash)
        rescue ::ActiveRecord::RecordNotFound => e
          raise Dao::Gateway::RecordNotFound, e.message
        rescue Exception => e
          rescue_with_handler(e) || raise
        end

        def delete(domain_id)
          record(domain_id).destroy if domain_id.present?
        end

        def chain(scope, method_name, args, &block)
          scope.public_send(method_name, *args, &block)
        rescue ::ActiveRecord::RecordNotFound => e
          raise Dao::Gateway::RecordNotFound, e.message
        end

        def add_relations(scope, relations, options)
          case options[:strategy]
            when :preload
              scope.preload(*relations)
            when :includes
              scope.includes(*relations)
            else
              scope.eager_load(*relations)
          end
        end

        def with_transaction(&block)
          source.transaction(&block)<commit_msg>add record not unique exception<commit_after>module Dao
  module Gateway
    module ActiveRecord
      class Base < Dao::Gateway::Base
        include ActiveSupport::Rescuable

        def initialize(source, transformer)
          super
          @black_list_attributes += source_relations
        end

        def save!(domain, attributes)
          record = export(domain, record(domain.id))
          record.assign_attributes(attributes)
          record.save!
          domain.attributes = import(record, domain.initialized_with).attributes
          domain
        rescue ::ActiveRecord::RecordInvalid
          raise Dao::Gateway::InvalidRecord.new(record.errors.to_hash)
        rescue ::ActiveRecord::RecordNotFound => e
          raise Dao::Gateway::RecordNotFound, e.message
        rescue ::ActiveRecord::RecordNotUnique => e
          raise Dao::Gateway::RecordNotUnique, e.message
        rescue Exception => e
          rescue_with_handler(e) || raise
        end

        def delete(domain_id)
          record(domain_id).destroy if domain_id.present?
        end

        def chain(scope, method_name, args, &block)
          scope.public_send(method_name, *args, &block)
        rescue ::ActiveRecord::RecordNotFound => e
          raise Dao::Gateway::RecordNotFound, e.message
        end

        def add_relations(scope, relations, options)
          case options[:strategy]
            when :preload
              scope.preload(*relations)
            when :includes
              scope.includes(*relations)
            else
              scope.eager_load(*relations)
          end
        end

        def with_transaction(&block)
          source.transaction(&block)
{'fraction_non_alphanumeric': 0.08366656413411258, 'fraction_numerical': 0.0, 'mean_word_length': 2.1851126346718903, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '350824', 'n_tokens_mistral': 814, 'n_tokens_neox': 808, 'n_words': 181}