A very simple multi-tenant library for ruby with mongodb (based on mongoid).
Add this line to your application's Gemfile:
gem 'simple_tenant'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_tenant
Model definition:
class TestModel
include Mongoid::Document
include SimpleTenant::ModelExtensions
field :name, type: String
field :number, type: Integer
field :text, type: String
field :deleted_at, type: Time
field :tenant_id, type: Integer
tenanted_by :tenant_id
default_scope { where(deleted_at: nil) }
end
and:
TestModel.create name: 'document with tenant', tenant_id: 828
TestModel.create name: 'document with another tenant', tenant_id: 1113
TestModel.create name: 'document without tenant'
SimpleTenant.current_tenant = 828
TestModel.count # => 1
TestModel.first.name # ==> document with tenant
See more usage example in specs: