<commit_before>require 'uniq_validator'
class User < MongoBase
  
  
  def self.add_delegate(key)
    eval %{
      def #{key.to_s} 
        read_attribute_for_validation(:#{key.to_s})
      end
    
     def #{key}=(val) 
        set_attribute_value('#{key.to_s}',val)
     end
    }
  end
  
  add_delegate :password
  add_delegate :username
  add_delegate :first_name
  add_delegate :last_name
  add_delegate :email
  
  add_delegate :locked
  add_delegate :reset_key
  add_delegate :verified
  add_delegate :verify_key
  add_delegate :_id
  
  include ActiveModel::Validations
  
  validates_presence_of :first_name, :last_name
  validates :email, :presence => true, 
                    :length => {:minimum => 3, :maximum => 254},
                    :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i},
                    :uniq=>true
  validates :username, :presence => true,:length => {:minimum => 3, :maximum => 254}
  validates :username, :uniq=>true, :if=>:new_record?
  validates :password, :presence =>true,
                      :length => { :minimum => 5, :maximum => 40 }, :confirmation=>true


  add_delegate :password_confirmation

  # Lookup a user by the username and password,
  # param [String] username the username to look for
  # param [Sting] password the clear text password to look for, pass will be hashed to check                     
  def self.authenticate(username, password)
   u = mongo['users'].find_one({username:username, password:<PASSWORD>(password)})
   return User.new(u) if u   
  end


  # See if the username already exists
  # param [String] username
  def self.check_username(username)
    mongo['users'].find_one({username:attributes[:username]})
  end
  
  # Find users based on hash of key value pairs
  # param [Hash] params key value pairs to use as a filter - same as would be passed to mongo collection
  def self.find(params)
    mongo['users'].find(params).collect{|u| User.new(u)}
  end
<commit_msg>Replacing eval with define_method<commit_after>require 'uniq_validator'
class User < MongoBase
  
  
  def self.add_delegate(key)
    define_method(key) do
      read_attribute_for_validation(key)
    end
    
    define_method("#{key.to_s}=".to_sym) do |val|
      set_attribute_value(key, val)
    end
  end
  
  add_delegate :password
  add_delegate :username
  add_delegate :first_name
  add_delegate :last_name
  add_delegate :email
  
  add_delegate :locked
  add_delegate :reset_key
  add_delegate :verified
  add_delegate :verify_key
  add_delegate :_id
  
  include ActiveModel::Validations
  
  validates_presence_of :first_name, :last_name
  validates :email, :presence => true, 
                    :length => {:minimum => 3, :maximum => 254},
                    :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i},
                    :uniq=>true
  validates :username, :presence => true, :length => {:minimum => 3, :maximum => 254}
  validates :username, :uniq=>true, :if => :new_record?
  validates :password, :presence =>true,
                      :length => { :minimum => 5, :maximum => 40 }, :confirmation=>true


  add_delegate :password_confirmation

  # Lookup a user by the username and password,
  # param [String] username the username to look for
  # param [Sting] password the clear text password to look for, pass will be hashed to check                     
  def self.authenticate(username, password)
   u = mongo['users'].find_one({username:username, password:hash_password(password)})
   return User.new(u) if u   
  end


  # See if the username already exists
  # param [String] username
  def self.check_username(username)
    mongo['users'].find_one({username:attributes[:username]})
  end
  
  # Find users based on hash of key value pairs
  # param [Hash] params key value pairs to use as a filter - same as would be passed to mongo collection
  def self.find(params)
    mongo['users'].find(params).collect{|u| User.new(u)}
  end

{'fraction_non_alphanumeric': 0.1213653603034134, 'fraction_numerical': 0.007079646017699115, 'mean_word_length': 3.1685985247629085, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 40, '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': '6392518', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1232, 'n_words': 342}