multitenancy-rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +3 -0
- data/AGENTS.md +67 -0
- data/CLAUDE.md +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +574 -0
- data/Rakefile +10 -0
- data/docs/README.md +72 -0
- data/docs/api.md +130 -0
- data/docs/generator.md +88 -0
- data/docs/getting-started.md +111 -0
- data/docs/integrations.md +145 -0
- data/docs/rake-tasks.md +53 -0
- data/docs/themes.md +159 -0
- data/lib/generators/multitenancy/multitenancy_generator.rb +88 -0
- data/lib/generators/multitenancy/templates/application_controller.rb +7 -0
- data/lib/generators/multitenancy/templates/home/index.html.erb +2 -0
- data/lib/generators/multitenancy/templates/home_controller.rb +9 -0
- data/lib/generators/multitenancy/templates/importmap.rb +4 -0
- data/lib/generators/multitenancy/templates/javascript/application.js +12 -0
- data/lib/generators/multitenancy/templates/javascript/controllers/hello_controller.js +7 -0
- data/lib/generators/multitenancy/templates/layouts/application.html.erb +32 -0
- data/lib/generators/multitenancy/templates/locales/en.yml +4 -0
- data/lib/generators/multitenancy/templates/routes.rb +6 -0
- data/lib/generators/multitenancy/templates/stylesheets/application.css +13 -0
- data/lib/generators/multitenancy/templates/tailwind/application.css +4 -0
- data/lib/multitenancy/controller.rb +25 -0
- data/lib/multitenancy/integrations/factory_bot.rb +15 -0
- data/lib/multitenancy/integrations/importmap.rb +79 -0
- data/lib/multitenancy/integrations/minitest.rb +49 -0
- data/lib/multitenancy/integrations/rails.rb +15 -0
- data/lib/multitenancy/integrations/rspec.rb +58 -0
- data/lib/multitenancy/integrations/tailwind_css.rb +51 -0
- data/lib/multitenancy/integrations.rb +12 -0
- data/lib/multitenancy/rails.rb +8 -0
- data/lib/multitenancy/railtie.rb +32 -0
- data/lib/multitenancy/stim.rb +39 -0
- data/lib/multitenancy/theme.rb +66 -0
- data/lib/multitenancy/version.rb +5 -0
- data/lib/multitenancy-rails.rb +1 -0
- data/lib/multitenancy.rb +74 -0
- data/lib/tasks/multitenancy_tailwindcss.rake +58 -0
- metadata +141 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 94cb822ac6240e6f4f613e4493b71f1e6c11e1526d923dc15f0f86fd554840ba
|
|
4
|
+
data.tar.gz: f031e768ca8765548fb9caa703d2fa3b5c017c8ae82ed7e5178ec74224610832
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9065c1c25494966502f9b213be87048cf3ef8f5d19a6984db9f93c399768ffaa673f5e4091ae00bd3ed0237ae0b89a87a106869970126b57fc6d918746e618cb
|
|
7
|
+
data.tar.gz: 07d5a7e99984085c71160f714ff91cebb7008ff2d0e5e0e13dbddbb6344f0feaa1c944623480efe6f671d24ab4dc0e1d73b41757e086b0beb6de15acb20b6c39
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/AGENTS.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run all tests and linting (default task)
|
|
9
|
+
bundle exec rake
|
|
10
|
+
|
|
11
|
+
# Run tests only
|
|
12
|
+
bundle exec rspec
|
|
13
|
+
|
|
14
|
+
# Run a single spec file
|
|
15
|
+
bundle exec rspec spec/multitenancy/theme_spec.rb
|
|
16
|
+
|
|
17
|
+
# Run a single example by line number
|
|
18
|
+
bundle exec rspec spec/multitenancy/theme_spec.rb:42
|
|
19
|
+
|
|
20
|
+
# Lint
|
|
21
|
+
bundle exec standardrb
|
|
22
|
+
|
|
23
|
+
# Auto-fix lint issues
|
|
24
|
+
bundle exec standardrb --fix
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
This is a Rails gem that implements multitenancy via **per-theme Rails Engines** created dynamically at boot time. Each theme under `themes/` in the host app gets its own isolated engine, namespace, autoload paths, views, assets, and routes.
|
|
30
|
+
|
|
31
|
+
### Core flow
|
|
32
|
+
|
|
33
|
+
1. **`Multitenancy::Railtie`** hooks into `before_configuration` and `after_initialize`.
|
|
34
|
+
2. During `before_configuration`, `Integrations::Rails` calls `Theme#bootstrap(app)` for every directory under `themes/`.
|
|
35
|
+
3. `Theme#bootstrap` creates a Ruby module (`Themes::MyStore`), then a `Rails::Engine` subclass (`Themes::MyStore::Engine`) by calling `Theme#create_engine`, which includes a `Stim` instance as a mixin.
|
|
36
|
+
4. **`Stim`** (a `Module` subclass) is the engine configurator: it sets `called_from`, `isolate_namespace`, `config.root`, and registers `app/views`, `app/assets`, `config/locales`, `app/javascript` paths on the engine.
|
|
37
|
+
5. `Theme#inject_paths` registers the theme's autoload directories (controllers, models, services, etc.) with Zeitwerk under the theme's namespace, and adds `app/javascript` to Propshaft's asset paths.
|
|
38
|
+
|
|
39
|
+
### Key files
|
|
40
|
+
|
|
41
|
+
| File | Role |
|
|
42
|
+
|------|------|
|
|
43
|
+
| `lib/multitenancy.rb` | Entry point; defines `Multitenancy.themes`, `config.paths`, and triggers Railtie load |
|
|
44
|
+
| `lib/multitenancy/theme.rb` | Represents one theme; owns bootstrap, namespace/engine creation, path injection |
|
|
45
|
+
| `lib/multitenancy/stim.rb` | `Module` subclass used as an `include`-able engine configurator |
|
|
46
|
+
| `lib/multitenancy/controller.rb` | `ActiveSupport::Concern` included in theme application controllers; fixes view path and strips namespace from `_prefixes` |
|
|
47
|
+
| `lib/multitenancy/railtie.rb` | Wires integrations into the Rails boot lifecycle |
|
|
48
|
+
| `lib/multitenancy/integrations/` | Optional integrations (Importmap, TailwindCSS, RSpec, FactoryBot) — each uses a guard clause and is silently skipped if its gem is absent |
|
|
49
|
+
|
|
50
|
+
### Test setup
|
|
51
|
+
|
|
52
|
+
Specs run against a dummy Rails app at `spec/dummy/`. The `spec_helper.rb`:
|
|
53
|
+
- Sets `Multitenancy.root` to the dummy app root before each example
|
|
54
|
+
- Calls `Multitenancy.reset!` to clear the themes cache
|
|
55
|
+
- Stubs `autoloaders.main.push_dir` to avoid real Zeitwerk side effects
|
|
56
|
+
- Cleans up dynamically created `Themes::*` constants after each example
|
|
57
|
+
|
|
58
|
+
The `FakeThemeHelpers` and `RailsStateCleanup` support modules in `spec/support/` provide helpers for creating temporary theme directory structures in tests and restoring Rails global state.
|
|
59
|
+
|
|
60
|
+
### Integration pattern
|
|
61
|
+
|
|
62
|
+
Each integration in `lib/multitenancy/integrations/` follows the same pattern: a class with a single `.call(app)` class method, guarded at the top against the optional gem not being present. New integrations should follow this convention.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Commits and Pull Requests
|
|
66
|
+
|
|
67
|
+
Commits and pull requests should be brief and to the point. Do not include "Co-authored-by" or mention Claude, Codex, OpenCode, Crush in commit messages.
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run all tests and linting (default task)
|
|
9
|
+
bundle exec rake
|
|
10
|
+
|
|
11
|
+
# Run tests only
|
|
12
|
+
bundle exec rspec
|
|
13
|
+
|
|
14
|
+
# Run a single spec file
|
|
15
|
+
bundle exec rspec spec/multitenancy/theme_spec.rb
|
|
16
|
+
|
|
17
|
+
# Run a single example by line number
|
|
18
|
+
bundle exec rspec spec/multitenancy/theme_spec.rb:42
|
|
19
|
+
|
|
20
|
+
# Lint
|
|
21
|
+
bundle exec standardrb
|
|
22
|
+
|
|
23
|
+
# Auto-fix lint issues
|
|
24
|
+
bundle exec standardrb --fix
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
This is a Rails gem that implements multitenancy via **per-theme Rails Engines** created dynamically at boot time. Each theme under `themes/` in the host app gets its own isolated engine, namespace, autoload paths, views, assets, and routes.
|
|
30
|
+
|
|
31
|
+
### Core flow
|
|
32
|
+
|
|
33
|
+
1. **`Multitenancy::Railtie`** hooks into `before_configuration` and `after_initialize`.
|
|
34
|
+
2. During `before_configuration`, `Integrations::Rails` calls `Theme#bootstrap(app)` for every directory under `themes/`.
|
|
35
|
+
3. `Theme#bootstrap` creates a Ruby module (`Themes::MyStore`), then a `Rails::Engine` subclass (`Themes::MyStore::Engine`) by calling `Theme#create_engine`, which includes a `Stim` instance as a mixin.
|
|
36
|
+
4. **`Stim`** (a `Module` subclass) is the engine configurator: it sets `called_from`, `isolate_namespace`, `config.root`, and registers `app/views`, `app/assets`, `config/locales`, `app/javascript` paths on the engine.
|
|
37
|
+
5. `Theme#inject_paths` registers the theme's autoload directories (controllers, models, services, etc.) with Zeitwerk under the theme's namespace, and adds `app/javascript` to Propshaft's asset paths.
|
|
38
|
+
|
|
39
|
+
### Key files
|
|
40
|
+
|
|
41
|
+
| File | Role |
|
|
42
|
+
|------|------|
|
|
43
|
+
| `lib/multitenancy.rb` | Entry point; defines `Multitenancy.themes`, `config.paths`, and triggers Railtie load |
|
|
44
|
+
| `lib/multitenancy/theme.rb` | Represents one theme; owns bootstrap, namespace/engine creation, path injection |
|
|
45
|
+
| `lib/multitenancy/stim.rb` | `Module` subclass used as an `include`-able engine configurator |
|
|
46
|
+
| `lib/multitenancy/controller.rb` | `ActiveSupport::Concern` included in theme application controllers; fixes view path and strips namespace from `_prefixes` |
|
|
47
|
+
| `lib/multitenancy/railtie.rb` | Wires integrations into the Rails boot lifecycle |
|
|
48
|
+
| `lib/multitenancy/integrations/` | Optional integrations (Importmap, TailwindCSS, RSpec, FactoryBot) — each uses a guard clause and is silently skipped if its gem is absent |
|
|
49
|
+
|
|
50
|
+
### Test setup
|
|
51
|
+
|
|
52
|
+
Specs run against a dummy Rails app at `spec/dummy/`. The `spec_helper.rb`:
|
|
53
|
+
- Sets `Multitenancy.root` to the dummy app root before each example
|
|
54
|
+
- Calls `Multitenancy.reset!` to clear the themes cache
|
|
55
|
+
- Stubs `autoloaders.main.push_dir` to avoid real Zeitwerk side effects
|
|
56
|
+
- Cleans up dynamically created `Themes::*` constants after each example
|
|
57
|
+
|
|
58
|
+
The `FakeThemeHelpers` and `RailsStateCleanup` support modules in `spec/support/` provide helpers for creating temporary theme directory structures in tests and restoring Rails global state.
|
|
59
|
+
|
|
60
|
+
### Integration pattern
|
|
61
|
+
|
|
62
|
+
Each integration in `lib/multitenancy/integrations/` follows the same pattern: a class with a single `.call(app)` class method, guarded at the top against the optional gem not being present. New integrations should follow this convention.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Commits and Pull Requests
|
|
66
|
+
|
|
67
|
+
Commits and pull requests should be brief and to the point. Do not include "Co-authored-by" or mention Claude, Codex, OpenCode, Crush in commit messages.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Marcos G. Zimmermann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|