Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simply_the_tenant

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simply_the_tenant

  • 0.2.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Gem Version ci

SimplyTheTenant

Short description and motivation.

A simpler alternative to acts_as_tenant. For most applications acts_as_tenant is probably what you should reach for, it's battletested, and more feature rich.

So, that begs the question, what is the point of this gem at all?

  1. I just kinda wanted to write a multitenancy gem. For basically any applications, prefer acts_as_tenant, since it's battletested.
  2. acts_as_tenant uses ActiveSupport::CurrentAttributes under the hood, but that isn't exposed to the user. While that isn't exactly hard to add with acts_as_tenant, simply_the_tenant does this out of the box.
  3. simply_the_tenant adheres to your domain model. Current.account vs current_tenant, making things marginally easier to reason about.
  4. simply_the_tenant uses Rails 7 query_constraints, so certain queries will use compound indices, which is nice for anyone who wants to use composite primary keys or sharding.
  5. simply_the_tenant requires explicit scoping to access the data of a tenant or to access global data.

Overall, acts_as_tenant does do all of the things this gem does. simply_the_tenant just presents them in a different way and provides less configuration options. If that pleases you, feel free to use simply_the_tenant instead!

Installation

Add this line to your application's Gemfile:

gem "simply_the_tenant"

Getting started

Setting up simply_the_tenant is essentially identical to acts_as_tenant. But, a thing to keep in mind is that simply_the_tenatn is strict about naming. There is currently no way to tell simply_the_tenant what foreign key to use.

Model Setup

class MyTenant < ApplicationRecord
  simply_the_tenant
end

Anything that belongs to the MyTenant must have a my_tenant_id column.

class User < ApplicationRecord
  belongs_to_tenant :my_tenant
end

This will set up a default scope, query constraints, automatic setting of my_tenant_id and validations for the tenant.

You'll also need to setup a Current model if you don't already have one.

class Current < ActiveSupport::CurrentAttributes
  attribute :my_tenant
end

Controller Setup

simply_the_tenant uses the last subdomain from a request to determine the tenant to scope a given request to. There is currently no way to change this in simple_tenant

class ApplicationController < ActionController::Base
  sets_current_tenant :my_tenant

  def some_cool_action
    # Current.my_tenant is accessible here automatically
  end
end

Background Processing

simply_the_tenant currently doesn't support automatically setting the tenant for any background processing libraries out of the box. This will change shortly.

Testing

simply_the_tenant also doesn't support automatically setting the tenant for any testing libraries out of the box. This will change shortly.

Contributing

  1. Fork the repo
  2. Make changes
  3. Run the tests bundle exec appraisals bin/test
  4. Run the linter bundle exec rubocop
  5. Submit a PR

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 03 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc