<commit_before># encoding: utf-8

require 'fast_gettext'
module Noosfero

  def self.root(default = nil)
    ENV.fetch('RAILS_RELATIVE_URL_ROOT', default)
  end

  def self.pattern_for_controllers_in_directory(dir)
    disjunction = controllers_in_directory(dir).join('|')
    pattern = disjunction.blank? ? '' : ('(' + disjunction + ')')
    Regexp.new(pattern)
  end

  class << self
    def locales
      @locales ||= {
        'en' => 'English',
        'pt' => 'Português',
        'fr' => 'Français',
        'hy' => 'հայերեն լեզու',
        'de' => 'Deutsch',
        'ru' => 'русский язык',
        'es' => 'Español',
        'eo' => 'Esperanto',
        'it' => 'Italiano'
      }
    end
    attr_writer :locales
    attr_accessor :default_locale
    def available_locales
      @available_locales ||=
        begin
          locales_list = locales.keys
          # move English to the beginning
          if locales_list.include?('en')
            locales_list = ['en'] + (locales_list - ['en']).sort
          end
          locales_list
        end
    end
    def each_locale
      locales.keys.sort.each do |key|
        yield(key, locales[key])
      end
    end
    def with_locale(locale)
      orig_locale = FastGettext.locale
      FastGettext.set_locale(locale)
      yield
      FastGettext.set_locale(orig_locale)
    end
  end

  def self.identifier_format
    '[a-z0-9][a-z0-9~.]*([_\-][a-z0-9~.]+)*'
  end

  def self.default_hostname
    Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost'
  end

  private

  def self.controllers_in_directory(dir)
    app_controller_path = Dir.glob(Rails.root.join('app', 'controllers', dir, '*_controller.rb'))
    app_controller_path.map do |item|
      item.gsub(/^.*\/([^\/]+)_controller.rb$/, '\1')<commit_msg>Limit profile identifier pattern<commit_after># encoding: utf-8

require 'fast_gettext'
module Noosfero

  def self.root(default = nil)
    ENV.fetch('RAILS_RELATIVE_URL_ROOT', default)
  end

  def self.pattern_for_controllers_in_directory(dir)
    disjunction = controllers_in_directory(dir).join('|')
    pattern = disjunction.blank? ? '' : ('(' + disjunction + ')')
    Regexp.new(pattern)
  end

  class << self
    def locales
      @locales ||= {
        'en' => 'English',
        'pt' => 'Português',
        'fr' => 'Français',
        'hy' => 'հայերեն լեզու',
        'de' => 'Deutsch',
        'ru' => 'русский язык',
        'es' => 'Español',
        'eo' => 'Esperanto',
        'it' => 'Italiano'
      }
    end
    attr_writer :locales
    attr_accessor :default_locale
    def available_locales
      @available_locales ||=
        begin
          locales_list = locales.keys
          # move English to the beginning
          if locales_list.include?('en')
            locales_list = ['en'] + (locales_list - ['en']).sort
          end
          locales_list
        end
    end
    def each_locale
      locales.keys.sort.each do |key|
        yield(key, locales[key])
      end
    end
    def with_locale(locale)
      orig_locale = FastGettext.locale
      FastGettext.set_locale(locale)
      yield
      FastGettext.set_locale(orig_locale)
    end
  end

  def self.identifier_format
    '(?!index)[a-z0-9][a-z0-9~.]*([_\-][a-z0-9~.]+)*'
  end

  def self.default_hostname
    Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost'
  end

  private

  def self.controllers_in_directory(dir)
    app_controller_path = Dir.glob(Rails.root.join('app', 'controllers', dir, '*_controller.rb'))
    app_controller_path.map do |item|
      item.gsub(/^.*\/([^\/]+)_controller.rb$/, '\1')
{'fraction_non_alphanumeric': 0.14130434782608695, 'fraction_numerical': 0.004347826086956522, 'mean_word_length': 2.5326295585412666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '4961573', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1283, 'n_words': 232}