Skip to content

Latest commit

 

History

History
100 lines (67 loc) · 3.14 KB

README.md

File metadata and controls

100 lines (67 loc) · 3.14 KB

Solidus Act As Tenant

CircleCI codecov

This extension adds multi-tenant support to solidus using the row-level tenancy acts_as_tenant gem.

It adds tenant scoping to a configurabale set of models and adds a console utility to switch between tenants.

Installation

Add solidus_act_as_tenant to your Gemfile:

gem 'solidus_act_as_tenant'

Bundle your dependencies and run the installation generator:

bin/rails generate solidus_act_as_tenant:install

Usage

See the acts_as_tenant gem for an explanation of how tenant scoping works.

To configure this extension for your project, see:

  • The generated migration files
  • The generated tenant_aware_models.yml file
  • The generated initializer.rb file

There is also a console utility that can be used to simply manage tenants in the console. To use it, you can add it to your ~/.irbrc file or ~/.pryrc file:

if defined?(Rails)
  TS = SolidusActAsTenant::Utils::TenantSelector.new

  IRB.conf[:IRB_RC] = proc do
    #   * TS.ask             => anytime in console, to switch tenant from a list
    #   * TS.current         => same as Apartment::Tenant.current
    #   * TS.tenants         => hash of tenants. Example: { 0 => "Demo Company" }
    #   * TS.switch_tenant!(tenant_name) => same as ActsAsTenant.current_tenant = Tenant.find_by(name: tenant_name)
    TS.ask
  end
end

Development

Testing the extension

First bundle your dependencies, then run bin/rake. bin/rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using bin/rake extension:test_app.

bin/rake

To run Rubocop static code analysis run

bundle exec rubocop

When testing your application's integration with this extension you may use its factories. You can load Solidus core factories along with this extension's factories using this statement:

SolidusDevSupport::TestingSupport::Factories.load_for(SolidusActAsTenant::Engine)

Running the sandbox

To run this extension in a sandboxed Solidus application, you can run bin/sandbox. The path for the sandbox app is ./sandbox and bin/rails will forward any Rails commands to sandbox/bin/rails.

Here's an example:

$ bin/rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop

Releasing new versions

Please refer to the dedicated page in the Solidus wiki.

License

Copyright (c) 2024 Solidus Contrib, released under the New BSD License.