<commit_before>class Site
  include Singleton

  include Mongoid::Document

  field :subdomain,        :type => Boolean, :default => false      # Use subdomain or not.
  field :specifical_index, :type => Boolean, :default => false      # Use specifical index page or not. If it's true, '/' will redirect to 'welcome#index'.
  field :forum,            :type => String                          # Default forum. If it's nil, will be the first forum
  field :theme,            :type => String,  :default => 'spready'  # Default theme
  
  # serialized attributes for cache.
  cattr_reader :settings
  @@settings = YAML.load(Site.instance.attributes.to_yaml)

  # When Site.instance.save, need refresh settings
  after_save :reload_settings

  # Use method missing to do like Site.subdomain.
  def self.method_missing(method, *args, &block)
    if settings.key?(method.to_s)
      settings[method.to_s]
    else
      super
    end
  end

  protected
  
  def reload_settings
    @@settings = YAML.load(Site.instance.attributes.to_yaml)
  end

end<commit_msg>Change site mode<commit_after>class Site
  include Singleton

  include Mongoid::Document

  field :subdomain,        :type => Boolean, :default => false      # Use subdomain or not.
  field :specifical_index, :type => Boolean, :default => false      # Use specifical index page or not. If it's true, '/' will redirect to 'welcome#index'.
  field :forum,            :type => String                          # Default forum. If it's nil, will be the first forum
  field :theme,            :type => String,  :default => 'spready'  # Default theme
  
  private_class_method :create

  @@__instance = nil

  def self.instance
    return @@__instance if @@__instance
    Mutex.new.synchronize do
      @@__instance = self.first || create()
    end
  end

  # serialized attributes for cache.
  cattr_reader :settings

  # When Site.instance be saved, need refresh settings.
  after_save :reload_settings

  # Use method missing to do like Site.subdomain.
  def self.method_missing(method, *args, &block)
    if settings.key?(method.to_s)
      settings[method.to_s]
    else
      super
    end
  end

  protected
  
  def reload_settings
    @@settings = YAML.load(@@__instance.attributes.to_yaml)
  end

end
{'fraction_non_alphanumeric': 0.09433126660761736, 'fraction_numerical': 0.0, 'mean_word_length': 2.777591973244147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7203760', 'n_tokens_mistral': 690, 'n_tokens_neox': 660, 'n_words': 212}