class TenantsHelper::Tenants

Public Class Methods

new(tenants_config_hash:) click to toggle source
# File lib/tenants_helper/tenants.rb, line 4
def initialize(tenants_config_hash:)
  @tenants = QueryableCollection.create(
    tenants_config_hash.map { |id, attributes|
      new_attributes = attributes.rekey
      Tenant.new(new_attributes.merge(id: id))
    },
    Tenant.anima.attribute_names
  )
end

Public Instance Methods

find(id) click to toggle source
# File lib/tenants_helper/tenants.rb, line 24
def find(id)
  find_by!(id: id)
end
find_by(query) click to toggle source
# File lib/tenants_helper/tenants.rb, line 14
def find_by(query)
  @tenants.find_by(query)
end
find_by!(query) click to toggle source
# File lib/tenants_helper/tenants.rb, line 18
def find_by!(query)
  find_by(query) ||
    fail(ArgumentError,
         "Could not find Tenant for #{query.inspect}")
end
name_to_id(name) click to toggle source
# File lib/tenants_helper/tenants.rb, line 32
def name_to_id(name)
  tenant = find_by(name: name)
  return nil unless tenant
  tenant.id
end
valid?(id) click to toggle source
# File lib/tenants_helper/tenants.rb, line 28
def valid?(id)
  !find_by(id: id).nil?
end