<commit_before>if defined?(ActiveRecord::Base)
  module AttrEncrypted
    module Adapters
      module ActiveRecord
        def self.extended(base) # :nodoc:
          base.class_eval do
            attr_encrypted_options[:encode] = true
            class << self
              alias_method_chain :method_missing, :attr_encrypted
              if ::ActiveRecord::VERSION::STRING < "3"
                alias_method :undefine_attribute_methods, :reset_column_information
              end
            end

            if ::ActiveRecord::VERSION::STRING < "3.0" || ::ActiveRecord::VERSION::STRING > "3.1"
              def assign_attributes_with_attr_encrypted(*args)
                attributes = args.shift.symbolize_keys
                encrypted_attributes = self.class.encrypted_attributes.keys
                assign_attributes_without_attr_encrypted attributes.except(*encrypted_attributes), *args
                assign_attributes_without_attr_encrypted attributes.slice(*encrypted_attributes), *args
              end
              alias_method_chain :assign_attributes, :attr_encrypted
            else
              def attributes_with_attr_encrypted=(attributes)
                attributes = attributes.symbolize_keys
                encrypted_attributes = self.class.encrypted_attributes.keys
                self.attributes_without_attr_encrypted = attributes.except(*encrypted_attributes)
                self.attributes_without_attr_encrypted = attributes.slice(*encrypted_attributes)
              end
              alias_method_chain :attributes=, :attr_encrypted
            end
          end
        end

        protected

          # Ensures the attribute methods for db fields have been defined before calling the original 
          # <tt>attr_encrypted</tt> method<commit_msg>assignment of protected attributes was not working<commit_after>if defined?(ActiveRecord::Base)
  module AttrEncrypted
    module Adapters
      module ActiveRecord
        def self.extended(base) # :nodoc:
          base.class_eval do
            attr_encrypted_options[:encode] = true
            class << self
              alias_method_chain :method_missing, :attr_encrypted
              if ::ActiveRecord::VERSION::STRING < "3"
                alias_method :undefine_attribute_methods, :reset_column_information
              end
            end

            if ::ActiveRecord::VERSION::STRING < "3.0" || ::ActiveRecord::VERSION::STRING > "3.1"
              def assign_attributes_with_attr_encrypted(*args)
                attributes = args.shift.symbolize_keys
                encrypted_attributes = self.class.encrypted_attributes.keys
                assign_attributes_without_attr_encrypted attributes.except(*encrypted_attributes), *args
                assign_attributes_without_attr_encrypted attributes.slice(*encrypted_attributes), *args
              end
              alias_method_chain :assign_attributes, :attr_encrypted
            else
              def attributes_with_attr_encrypted=(*args)
                attributes = args.shift.symbolize_keys
                encrypted_attributes = self.class.encrypted_attributes.keys
                self.send :attributes_without_attr_encrypted=, attributes.except(*encrypted_attributes), *args
                self.send :attributes_without_attr_encrypted=, attributes.slice(*encrypted_attributes), *args
              end
              alias_method_chain :attributes=, :attr_encrypted
            end
          end
        end

        protected

          # Ensures the attribute methods for db fields have been defined before calling the original 
          # <tt>attr_encrypted</tt> method
{'fraction_non_alphanumeric': 0.06571741511500548, 'fraction_numerical': 0.002738225629791895, 'mean_word_length': 2.351376146788991, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '360305', 'n_tokens_mistral': 895, 'n_tokens_neox': 864, 'n_words': 177}