<commit_before># frozen_string_literal: true
module Monarchy
  class Member < ActiveRecord::Base
    self.table_name = 'monarchy_members'

    has_many :members_roles, dependent: :destroy
    has_many :roles, through: :members_roles

    belongs_to :user
    belongs_to :hierarchy

    delegate :resource, to: :hierarchy
    delegate :resource=, to: :hierarchy

    validates :user_id, uniqueness: { scope: :hierarchy_id }
    validates :user, presence: true
    validates :hierarchy, presence: true

    before_create :set_default_role

    private

    def set_default_role
      roles = self.roles
      roles << Monarchy::Role.find_or_create_by(
        name: Monarchy.configuration.default_role.name,
        inherited: Monarchy.configuration.default_role.inherited,
        level: Monarchy.configuration.default_role.level)
      self.roles = roles.uniq
    end
  end

  class Role < ActiveRecord::Base
    self.table_name = 'monarchy_roles'

    has_many :members_roles, dependent: :destroy
    has_many :members, through: :members_roles
  end

  class MembersRole < ActiveRecord::Base
    self.table_name = 'monarchy_members_roles'

    belongs_to :member
    belongs_to :role

    validates :role_id, uniqueness: { scope: :member_id }
  end
end
<commit_msg>Add missing class names<commit_after># frozen_string_literal: true
module Monarchy
  class Member < ActiveRecord::Base
    self.table_name = 'monarchy_members'

    has_many :members_roles, dependent: :destroy, class_name: 'Monarchy::MembersRole'
    has_many :roles, through: :members_roles, class_name: 'Monarchy::Roles'

    belongs_to :user
    belongs_to :hierarchy, class_name: 'Monarchy::Hierarchy'

    delegate :resource, to: :hierarchy
    delegate :resource=, to: :hierarchy

    validates :user_id, uniqueness: { scope: :hierarchy_id }
    validates :user, presence: true
    validates :hierarchy, presence: true

    before_create :set_default_role

    private

    def set_default_role
      roles = self.roles
      roles << Monarchy::Role.find_or_create_by(
        name: Monarchy.configuration.default_role.name,
        inherited: Monarchy.configuration.default_role.inherited,
        level: Monarchy.configuration.default_role.level)
      self.roles = roles.uniq
    end
  end

  class Role < ActiveRecord::Base
    self.table_name = 'monarchy_roles'

    has_many :members_roles, dependent: :destroy, class_name: 'Monarchy::MembersRole'
    has_many :members, through: :members_roles, class_name: 'Monarchy::Member'
  end

  class MembersRole < ActiveRecord::Base
    self.table_name = 'monarchy_members_roles'

    belongs_to :member, class_name: 'Monarchy::Member'
    belongs_to :role, class_name: 'Monarchy::Role'

    validates :role_id, uniqueness: { scope: :member_id }
  end
end

{'fraction_non_alphanumeric': 0.08861671469740634, 'fraction_numerical': 0.0, 'mean_word_length': 3.9589285714285714, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '4861837', 'n_tokens_mistral': 896, 'n_tokens_neox': 881, 'n_words': 201}