<commit_before>module LockerRoom
  module Models
    module Team
      extend ActiveSupport::Concern

      included do
        EXCLUDED_SUBDOMAINS ||= %w(admin test www new)

        has_many :users,     class_name: 'LockerRoom::User'
        has_many :mateships, class_name: 'LockerRoom::Mateship'
        has_many :ownerships,
          -> { where(:role => LockerRoom::Mateship.roles[:owner]) },
          class_name: 'LockerRoom::Mateship'
        has_many :owners,
          through: :ownerships,
          source:  :user
        accepts_nested_attributes_for :owners

        validates :name,
          presence: true
        validates :name,
          length:      {maximum: 32},
          allow_blank: true
        validates :subdomain,
          presence: true
        validates :subdomain,
          length:      {minimum: 3, maximum: 64},
          uniqueness:  true,
          allow_blank: true
        validates :subdomain,
          exclusion:   {in: EXCLUDED_SUBDOMAINS,
                        message: "%{value} is not allowed"},
          format:      {with: /\A[\w\-]+\Z/i,
                        message: "%{value} is not allowed"},
          allow_blank: true

        before_validation do
          self.subdomain = subdomain.to_s.downcase
        end

        def created?
          persisted? && (owner = owners.first) && owner.persisted?
        end

        def create_schema
          Apartment::Tenant.create(schema_name)
        end

        def schema_name
          subdomain.gsub(/\-/, '_')
        end
      end

      class_methods do
        def create_with_owner(options={})
          self.transaction do
            team = new(options)
            if team.save
              owner = team.owners.first
              unless owner && owner.update_attribute(:team, team)
                raise ActiveRecord::Rollback
              end
            end
            team<commit_msg>Fix quote issue<commit_after>module LockerRoom
  module Models
    module Team
      extend ActiveSupport::Concern

      included do
        EXCLUDED_SUBDOMAINS ||= %w(admin test www new)

        has_many :users,     class_name: 'LockerRoom::User'
        has_many :mateships, class_name: 'LockerRoom::Mateship'
        has_many :ownerships,
          -> { where(:role => LockerRoom::Mateship.roles[:owner]) },
          class_name: 'LockerRoom::Mateship'
        has_many :owners,
          through: :ownerships,
          source:  :user
        accepts_nested_attributes_for :owners

        validates :name,
          presence: true
        validates :name,
          length:      {maximum: 32},
          allow_blank: true
        validates :subdomain,
          presence: true
        validates :subdomain,
          length:      {minimum: 3, maximum: 64},
          uniqueness:  true,
          allow_blank: true
        validates :subdomain,
          exclusion:   {in: EXCLUDED_SUBDOMAINS,
                        message: '%{value} is not allowed'},
          format:      {with: /\A[\w\-]+\Z/i,
                        message: '%{value} is not allowed'},
          allow_blank: true

        before_validation do
          self.subdomain = subdomain.to_s.downcase
        end

        def created?
          persisted? && (owner = owners.first) && owner.persisted?
        end

        def create_schema
          Apartment::Tenant.create(schema_name)
        end

        def schema_name
          subdomain.gsub(/\-/, '_')
        end
      end

      class_methods do
        def create_with_owner(options={})
          self.transaction do
            team = new(options)
            if team.save
              owner = team.owners.first
              unless owner && owner.update_attribute(:team, team)
                raise ActiveRecord::Rollback
              end
            end
            team
{'fraction_non_alphanumeric': 0.08991113434396236, 'fraction_numerical': 0.0026136957658128594, 'mean_word_length': 1.6266300617707619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7033881', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1044, 'n_words': 251}