Sha256: e310d4ca7a3953a081fb673b2c2e0aa6240671fc316ca05370ee50d6ad5bce84

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

# A workaraound to get `reload!` to also call Apartment::Tenant.init
# This is unfortunate, but I haven't figured out how to hook into the reload process *after* files are reloaded

# reloads the environment
def reload!(print = true)
  # rubocop:disable Rails/Output
  puts 'Reloading...' if print
  # rubocop:enable Rails/Output

  # This triggers the to_prepare callbacks
  ActionDispatch::Callbacks.new(proc {}).call({})
  # Manually init Apartment again once classes are reloaded
  Apartment::Tenant.init
  true
end

def st(schema_name = nil)
  if schema_name.nil?
    # rubocop:disable Rails/Output
    tenant_list.each { |t| puts t }
    # rubocop:enable Rails/Output
  elsif tenant_list.include? schema_name
    Apartment::Tenant.switch!(schema_name)
  else
    # rubocop:disable Rails/Output
    puts "Tenant #{schema_name} is not part of the tenant list"
    # rubocop:enable Rails/Output
  end
end

def tenant_list
  tenant_list = [Apartment.default_tenant]
  tenant_list += Apartment.tenant_names
  tenant_list.uniq
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ros-apartment-2.5.0 lib/apartment/console.rb
ros-apartment-2.4.0 lib/apartment/console.rb