<commit_before>class MiqAeNamespace < ApplicationRecord
  acts_as_tree
  include MiqAeSetUserInfoMixin
  include MiqAeYamlImportExportMixin

  EXPORT_EXCLUDE_KEYS = [/^id$/, /_id$/, /^created_on/, /^updated_on/,
                         /^updated_by/, /^reserved$/, /^commit_message/,
                         /^commit_time/, /^commit_sha/, /^ref$/, /^ref_type$/,
                         /^last_import_on/, /^source/, /^top_level_namespace/].freeze

  belongs_to :parent,        :class_name => "MiqAeNamespace",  :foreign_key => :parent_id
  has_many   :ae_namespaces, :class_name => "MiqAeNamespace",  :foreign_key => :parent_id,    :dependent => :destroy
  has_many   :ae_classes, -> { includes([:ae_methods, :ae_fields, :ae_instances]) },    :class_name => "MiqAeClass",      :foreign_key => :namespace_id, :dependent => :destroy

  validates_presence_of   :name
  validates_format_of     :name, :with    => /\A[\w\.\-\$]+\z/i,
                                 :message => N_("may contain only alphanumeric and _ . - $ characters")
  validates_uniqueness_of :name, :scope => :parent_id

  def self.find_by_fqname(fqname, include_classes = true)
    return nil if fqname.blank?

    fqname   = fqname[0] == '/' ? fqname : "/#{fqname}"
    fqname   = fqname.downcase
    last     = fqname.split('/').last
    low_name = arel_table[:name].lower
    query    = includes(:parent)
    query    = query.includes(:ae_classes) if include_classes
    query.where(low_name.eq(last)).detect { |namespace| namespace.fqname.downcase == fqname }<commit_msg>Making name validation to not be case-sensitive.<commit_after>class MiqAeNamespace < ApplicationRecord
  acts_as_tree
  include MiqAeSetUserInfoMixin
  include MiqAeYamlImportExportMixin

  EXPORT_EXCLUDE_KEYS = [/^id$/, /_id$/, /^created_on/, /^updated_on/,
                         /^updated_by/, /^reserved$/, /^commit_message/,
                         /^commit_time/, /^commit_sha/, /^ref$/, /^ref_type$/,
                         /^last_import_on/, /^source/, /^top_level_namespace/].freeze

  belongs_to :parent,        :class_name => "MiqAeNamespace",  :foreign_key => :parent_id
  has_many   :ae_namespaces, :class_name => "MiqAeNamespace",  :foreign_key => :parent_id,    :dependent => :destroy
  has_many   :ae_classes, -> { includes([:ae_methods, :ae_fields, :ae_instances]) },    :class_name => "MiqAeClass",      :foreign_key => :namespace_id, :dependent => :destroy

  validates_presence_of   :name
  validates_format_of     :name, :with    => /\A[\w\.\-\$]+\z/i,
                                 :message => N_("may contain only alphanumeric and _ . - $ characters")
  validates_uniqueness_of :name, :scope => :parent_id, :case_sensitive => false

  def self.find_by_fqname(fqname, include_classes = true)
    return nil if fqname.blank?

    fqname   = fqname[0] == '/' ? fqname : "/#{fqname}"
    fqname   = fqname.downcase
    last     = fqname.split('/').last
    low_name = arel_table[:name].lower
    query    = includes(:parent)
    query    = query.includes(:ae_classes) if include_classes
    query.where(low_name.eq(last)).detect { |namespace| namespace.fqname.downcase == fqname }
{'fraction_non_alphanumeric': 0.14525848398350777, 'fraction_numerical': 0.0006343165239454488, 'mean_word_length': 2.913151364764268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397906', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1077, 'n_words': 194}