Module: Organizations::Models::Concerns::HasOrganizations::ClassMethods

Defined in:
lib/organizations/models/concerns/has_organizations.rb

Overview

Module containing class methods to be extended onto ActiveRecord::Base

Instance Method Summary collapse

Instance Method Details

#has_organizations(**options) { ... } ⇒ Object

Enable organization support on this model

Parameters:

  • options (Hash)

    Configuration options

Options Hash (**options):

  • :max_organizations (Integer, nil)

    Maximum orgs user can own

  • :create_personal_org (Boolean, Proc)

    Create personal org on signup. Can be a boolean or a proc that receives the user instance for conditional creation.

  • :require_organization (Boolean)

    Require user to have an org

Yields:

  • Configuration block using DSL



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/organizations/models/concerns/has_organizations.rb', line 47

def has_organizations(**options, &block)
  # Include instance methods
  include InstanceMethods

  # Define associations
  define_organization_associations

  # Define class_attribute for settings
  define_organization_settings(options, &block)

  # Setup callbacks for personal org creation
  setup_personal_org_callback

  # Preserve owner integrity on user deletion
  setup_owner_deletion_guard
end