<commit_before>class Profile < ActiveRecord::Base
  enju_circulation_profile_model if defined?(EnjuCirculation)
  enju_search_log_profile_model if defined?(EnjuSearchLog)

  scope :administrators, -> { joins(user: :role).where('roles.name = ?', 'Administrator') }
  scope :librarians, -> { joins(user: :role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
  belongs_to :user, dependent: :destroy
  belongs_to :library, validate: true
  belongs_to :user_group
  belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id' #, validate: true
  has_many :identities
  accepts_nested_attributes_for :identities, allow_destroy: true, reject_if: :all_blank

  validates_associated :user_group, :library
  validates_associated :user
  validates_presence_of :user_group, :library, :locale #, :user_number
  validates :user_number, uniqueness: true, format: { with: /\A[0-9A-Za-z_]+\z/ }, allow_blank: true
  validates :user_id, uniqueness: true, allow_blank: true
  validates :birth_date, format: { with: /\A\d{4}-\d{1,2}-\d{1,2}\z/ }, allow_blank: true

  normalize_attribute :user_number

  attr_accessor :birth_date

  searchable do
    text :user_number, :full_name, :full_name_transcription, :note
    string :user_number
    text :username do
      user.try(:username)
    end
    text :email do
      user.try(:email)
    end
    string :username do
      user.try(:username)
    end
    string :email do
      user.try(:email)
    end
    time :created_at
    time :updated_at
    boolean :active do
      user.try(:active_for_authentication?)
    end<commit_msg>use strip_attributes<commit_after>class Profile < ActiveRecord::Base
  enju_circulation_profile_model if defined?(EnjuCirculation)
  enju_search_log_profile_model if defined?(EnjuSearchLog)

  scope :administrators, -> { joins(user: :role).where('roles.name = ?', 'Administrator') }
  scope :librarians, -> { joins(user: :role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
  belongs_to :user, dependent: :destroy
  belongs_to :library, validate: true
  belongs_to :user_group
  belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id' #, validate: true
  has_many :identities
  accepts_nested_attributes_for :identities, allow_destroy: true, reject_if: :all_blank

  validates_associated :user_group, :library
  validates_associated :user
  validates_presence_of :user_group, :library, :locale #, :user_number
  validates :user_number, uniqueness: true, format: { with: /\A[0-9A-Za-z_]+\z/ }, allow_blank: true
  validates :user_id, uniqueness: true, allow_blank: true
  validates :birth_date, format: { with: /\A\d{4}-\d{1,2}-\d{1,2}\z/ }, allow_blank: true

  strip_attribute only: :user_number

  attr_accessor :birth_date

  searchable do
    text :user_number, :full_name, :full_name_transcription, :note
    string :user_number
    text :username do
      user.try(:username)
    end
    text :email do
      user.try(:email)
    end
    string :username do
      user.try(:username)
    end
    string :email do
      user.try(:email)
    end
    time :created_at
    time :updated_at
    boolean :active do
      user.try(:active_for_authentication?)
    end
{'fraction_non_alphanumeric': 0.11627906976744186, 'fraction_numerical': 0.004341085271317829, 'mean_word_length': 4.403685092127303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4586281', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1078, 'n_words': 245}