<commit_before># == Schema Information
#
# Table name: namespaces
#
#  id          :integer          not null, primary key
#  name        :string(255)      not null
#  path        :string(255)      not null
#  owner_id    :integer
#  created_at  :datetime
#  updated_at  :datetime
#  type        :string(255)
#  description :string(255)      default(""), not null
#  avatar      :string(255)
#

class Namespace < ActiveRecord::Base
  include Sortable
  include Gitlab::ShellAdapter

  has_many :projects, dependent: :destroy
  belongs_to :owner, class_name: "User"

  validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
  validates :name,
    presence: true, uniqueness: true,
    length: { within: 0..255 },
    format: { with: Gitlab::Regex.namespace_name_regex,
              message: Gitlab::Regex.namespace_name_regex_message }

  validates :description, length: { within: 0..255 }
  validates :path,
    uniqueness: { case_sensitive: false },
    presence: true,
    length: { within: 1..255 },
    exclusion: { in: Gitlab::Blacklist.path },
    format: { with: Gitlab::Regex.namespace_regex,
              message: Gitlab::Regex.namespace_regex_message }

  delegate :name, to: :owner, allow_nil: true, prefix: true

  after_create :ensure_dir_exist
  after_update :move_dir, if: :path_changed?
  after_destroy :rm_dir

  scope :root, -> { where('type IS NULL') }

  class << self
    def by_path(path)
      where('lower(path) = :value', value: path.downcase).first
    end

    # Case insensetive search for namespace by path or name
    def find_by_path_or_name(path)
      find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
    end

    def search(query)
      where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
    end

    def clean_path(path)
      path.gsub!(/@.*\z/,             "")
      path.gsub!(/\.git\z/,           "")
      path.gsub!(/\A-/,               "")
      path.gsub!(/\.+\z/,             "")<commit_msg>clean_path should drop all leading dashes, not just one<commit_after># == Schema Information
#
# Table name: namespaces
#
#  id          :integer          not null, primary key
#  name        :string(255)      not null
#  path        :string(255)      not null
#  owner_id    :integer
#  created_at  :datetime
#  updated_at  :datetime
#  type        :string(255)
#  description :string(255)      default(""), not null
#  avatar      :string(255)
#

class Namespace < ActiveRecord::Base
  include Sortable
  include Gitlab::ShellAdapter

  has_many :projects, dependent: :destroy
  belongs_to :owner, class_name: "User"

  validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
  validates :name,
    presence: true, uniqueness: true,
    length: { within: 0..255 },
    format: { with: Gitlab::Regex.namespace_name_regex,
              message: Gitlab::Regex.namespace_name_regex_message }

  validates :description, length: { within: 0..255 }
  validates :path,
    uniqueness: { case_sensitive: false },
    presence: true,
    length: { within: 1..255 },
    exclusion: { in: Gitlab::Blacklist.path },
    format: { with: Gitlab::Regex.namespace_regex,
              message: Gitlab::Regex.namespace_regex_message }

  delegate :name, to: :owner, allow_nil: true, prefix: true

  after_create :ensure_dir_exist
  after_update :move_dir, if: :path_changed?
  after_destroy :rm_dir

  scope :root, -> { where('type IS NULL') }

  class << self
    def by_path(path)
      where('lower(path) = :value', value: path.downcase).first
    end

    # Case insensetive search for namespace by path or name
    def find_by_path_or_name(path)
      find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
    end

    def search(query)
      where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
    end

    def clean_path(path)
      path.gsub!(/@.*\z/,             "")
      path.gsub!(/\.git\z/,           "")
      path.gsub!(/\A-+/,              "")
      path.gsub!(/\.+\z/,             "")
{'fraction_non_alphanumeric': 0.1349875930521092, 'fraction_numerical': 0.013399503722084368, 'mean_word_length': 2.7186346863468636, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1168548', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1297, 'n_words': 332}