<commit_before># Copyright (C) 2009 <NAME>.

require 'digest/sha1'

# Master ActiveRecord::Base class for all per-domain tables
class DomainModel < ActiveRecord::Base
  self.abstract_class = true
  @@active_domain = {} # Made Thread safe for Backgroundrb
  
  include HandlerActions
  include ModelExtension::OptionsExtension

  @@mutex = Mutex.new
  
  cattr_accessor :logger

  def self.process_id
    Thread.current.object_id
  end

  # Returns the active domain information hash
  def self.active_domain
    @@active_domain[process_id]  || {}
  end
  
  # Returns the active domain id from the Domain table
  def self.active_domain_id
    (@@active_domain[process_id]  || {})[:id].to_s
  end
  
  # Returns the name of the active domain
  def self.active_domain_name
    (@@active_domain[process_id]  ||{})[:name].to_s
  end
  
  # Returns the database of the active domain
  def self.active_domain_db
    (@@active_domain[process_id]  ||{})[:database].to_s
  end
  
  # Returns the name of the class
  #  (overridden in ContentModelType where self.to_s doesn't work)
  def self.class_name
    self.to_s
  end
  
  # Allow update to all attributes via a Hash, even 
  # protected attributes
  def update_all_attributes(atr = {})
    self.send("attributes=",atr,false)
    self.save
  end

  # Creates a belongs_to relationship with DomainFile
  # and adds DomainFileInstance support
  #
  # Use instead of belongs_to :domain_file
  def self.has_domain_file(field_name,options={})
    field = options[:relation] || field_name.to_s.gsub(/_id$/,'')

    belongs_to field, :class_name => 'DomainFile', :foreign_key => options[:foreign_key] || field_name
    domain_file_column(field_name)
  end

  # Used to paginate a list of entries, returns a pagination information hash
  # and a list of entries
  # <commit_msg>Fix for has_domain_file, belongs_to requires a symbol.<commit_after># Copyright (C) 2009 <NAME>.

require 'digest/sha1'

# Master ActiveRecord::Base class for all per-domain tables
class DomainModel < ActiveRecord::Base
  self.abstract_class = true
  @@active_domain = {} # Made Thread safe for Backgroundrb
  
  include HandlerActions
  include ModelExtension::OptionsExtension

  @@mutex = Mutex.new
  
  cattr_accessor :logger

  def self.process_id
    Thread.current.object_id
  end

  # Returns the active domain information hash
  def self.active_domain
    @@active_domain[process_id]  || {}
  end
  
  # Returns the active domain id from the Domain table
  def self.active_domain_id
    (@@active_domain[process_id]  || {})[:id].to_s
  end
  
  # Returns the name of the active domain
  def self.active_domain_name
    (@@active_domain[process_id]  ||{})[:name].to_s
  end
  
  # Returns the database of the active domain
  def self.active_domain_db
    (@@active_domain[process_id]  ||{})[:database].to_s
  end
  
  # Returns the name of the class
  #  (overridden in ContentModelType where self.to_s doesn't work)
  def self.class_name
    self.to_s
  end
  
  # Allow update to all attributes via a Hash, even 
  # protected attributes
  def update_all_attributes(atr = {})
    self.send("attributes=",atr,false)
    self.save
  end

  # Creates a belongs_to relationship with DomainFile
  # and adds DomainFileInstance support
  #
  # Use instead of belongs_to :domain_file
  def self.has_domain_file(field_name,options={})
    field = options[:relation] || field_name.to_s.gsub(/_id$/,'')

    belongs_to field.to_sym, :class_name => 'DomainFile', :foreign_key => options[:foreign_key] || field_name
    domain_file_column(field_name)
  end

  # Used to paginate a list of entries, returns a pagination information hash
  # and a list of entries
  # 
{'fraction_non_alphanumeric': 0.09266304347826088, 'fraction_numerical': 0.002717391304347826, 'mean_word_length': 3.8626155878467636, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3364531', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1152, 'n_words': 334}