rolemodel-rails 2.7.1 → 2.9.0
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 +4 -4
- data/README.md +13 -4
- data/exe/rmr +6 -0
- data/lib/generators/rolemodel/README.md +2 -0
- data/lib/generators/rolemodel/agent_docs/README.md +14 -0
- data/lib/generators/rolemodel/agent_docs/USAGE +10 -0
- data/lib/generators/rolemodel/agent_docs/agent_docs_generator.rb +22 -0
- data/lib/generators/rolemodel/agent_docs/templates/.claude/settings.json +15 -0
- data/lib/generators/rolemodel/agent_docs/templates/.github/instructions/conventions.instructions.md +9 -0
- data/lib/generators/rolemodel/agent_docs/templates/AGENTS.md.tt +26 -0
- data/lib/generators/rolemodel/agent_docs/templates/CLAUDE.md +1 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/CONVENTIONS.md +18 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/callbacks.md +5 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/controllers.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/eager-loading.md +5 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/logic-in-models.md +7 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/migrations.md +7 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/no-sql-strings.md +11 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/partial-locals.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reproduce-the-bug.md +5 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reuse-scopes.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/stimulus.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/string-enums.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/system-spec-assertions.md +17 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/test-layers.md +3 -0
- data/lib/generators/rolemodel/agent_docs/templates/docs/conventions/views-and-forms.md +9 -0
- data/lib/generators/rolemodel/all_generator.rb +2 -0
- data/lib/generators/rolemodel/core_setup/README.md +4 -0
- data/lib/generators/rolemodel/core_setup/USAGE +4 -4
- data/lib/generators/rolemodel/core_setup/core_setup_generator.rb +4 -1
- data/lib/generators/rolemodel/dotenv/README.md +110 -0
- data/lib/generators/rolemodel/dotenv/USAGE +15 -0
- data/lib/generators/rolemodel/dotenv/dotenv_generator.rb +43 -0
- data/lib/generators/rolemodel/dotenv/templates/lib/env_value.rb +66 -0
- data/lib/generators/rolemodel/dotenv/templates/spec/lib/env_value_spec.rb +178 -0
- data/lib/generators/rolemodel/editors/editors_generator.rb +10 -13
- data/lib/generators/rolemodel/good_job/good_job_generator.rb +5 -1
- data/lib/generators/rolemodel/good_job/templates/config/initializers/good_job.rb +1 -1
- data/lib/generators/rolemodel/heroku/heroku_generator.rb +4 -9
- data/lib/generators/rolemodel/heroku/templates/deploy-app/SKILL.md +1 -1
- data/lib/generators/rolemodel/linters/eslint/eslint_generator.rb +0 -1
- data/lib/generators/rolemodel/linters/rubocop/templates/.rubocop.yml +17 -0
- data/lib/generators/rolemodel/mailers/mailers_generator.rb +27 -47
- data/lib/generators/rolemodel/mailers/templates/app/mailers/staging_mailer_interceptor.rb +2 -3
- data/lib/generators/rolemodel/readme/templates/README.md.erb +3 -0
- data/lib/generators/rolemodel/saas/devise/devise_generator.rb +3 -23
- data/lib/generators/rolemodel/sentry/sentry_generator.rb +1 -0
- data/lib/generators/rolemodel/sentry/templates/config/initializers/sentry.rb +1 -1
- data/lib/generators/rolemodel/source_map/README.md +1 -1
- data/lib/generators/rolemodel/source_map/source_map_generator.rb +8 -4
- data/lib/generators/rolemodel/source_map/templates/lib/middleware/rolemodel/source_map.rb +1 -1
- data/lib/generators/rolemodel/testing/jasmine_playwright/jasmine_playwright_generator.rb +0 -1
- data/lib/generators/rolemodel/testing/vitest/vitest_generator.rb +0 -1
- data/lib/rolemodel/engine.rb +2 -0
- data/lib/rolemodel/file_content_helper.rb +191 -0
- data/lib/rolemodel/generator_base.rb +41 -2
- data/lib/rolemodel/new_app/template.rb +7 -0
- data/lib/rolemodel/new_app.rb +22 -0
- data/lib/rolemodel/version.rb +1 -1
- metadata +34 -4
- data/lib/generators/rolemodel/editors/vscode_helpers.rb +0 -22
- data/lib/rolemodel/replace_content_helper.rb +0 -29
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63e3a9bfa6cc68d95d3369e5647f9bae6b11e2947083dd8003c2ad86a1db0c89
|
|
4
|
+
data.tar.gz: 29deaf547ab04ea0bae3ff14a8c83079a95c9e1fc5d7f5d2ffe785fa23b62477
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9a30907245726ad02faff24a72d53931ad607671f4e750d92dcb4f9a35bc89f6bb6c76394e2adf5ef222b1891094d89ca4ba196859897c5d218c95aee27f176
|
|
7
|
+
data.tar.gz: 824b4870b4b0199527fcd17de1bb6be2159c885b211c8315d85d020f0734ca91a33251551ed307ad6cc5d467c8104a285edf966829b3a351769e0d9a7d7dc0e9
|
data/README.md
CHANGED
|
@@ -11,14 +11,21 @@ Attempts to solve the pain of:
|
|
|
11
11
|
* Our BestPractice learns don't often get ported into other projects as it isn't straightforward to do so
|
|
12
12
|
* There is an emerging pattern of libraries using generators (e.g. webpacker) to migrate a setup between library versions
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## New Apps
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Start a new app with `rmr`, which wraps `rails new`:
|
|
17
17
|
|
|
18
18
|
```shell
|
|
19
|
-
|
|
19
|
+
gem install rolemodel-rails
|
|
20
|
+
rmr new <app-name>
|
|
20
21
|
```
|
|
21
22
|
|
|
23
|
+
`rmr` passes `--database=postgresql --javascript=webpack --skip-kamal --skip-solid --skip-test` and a template that adds this gem and runs `rolemodel:core_setup`, which asks for an icon library (default Material). Flags in your `~/.railsrc` override those defaults, and flags on the command line override both.
|
|
24
|
+
|
|
25
|
+
## Existing Apps
|
|
26
|
+
|
|
27
|
+
The rolemodel-rails gem can be added to an existing Rails project.
|
|
28
|
+
|
|
22
29
|
The Devise generator requires your database to exist before running.
|
|
23
30
|
|
|
24
31
|
```shell
|
|
@@ -70,6 +77,7 @@ bin/rails g
|
|
|
70
77
|
## Generators
|
|
71
78
|
|
|
72
79
|
* [Core Setup](./lib/generators/rolemodel/core_setup)
|
|
80
|
+
* [Agent Docs](./lib/generators/rolemodel/agent_docs)
|
|
73
81
|
* [Github](./lib/generators/rolemodel/github)
|
|
74
82
|
* [Heroku](./lib/generators/rolemodel/heroku)
|
|
75
83
|
* [Readme](./lib/generators/rolemodel/readme)
|
|
@@ -109,6 +117,7 @@ bin/rails g
|
|
|
109
117
|
* [Tailored Select](./lib/generators/rolemodel/tailored_select)
|
|
110
118
|
* [Tom Select](./lib/generators/rolemodel/tom_select)
|
|
111
119
|
* [Lograge](./lib/generators/rolemodel/lograge)
|
|
120
|
+
* [Dotenv](./lib/generators/rolemodel/dotenv)
|
|
112
121
|
|
|
113
122
|
## Agent Skills
|
|
114
123
|
|
|
@@ -121,7 +130,7 @@ Generators that leave behind conventions a coding agent needs to follow also ins
|
|
|
121
130
|
| `rolemodel:turbo:modals` | `turbo-modals` |
|
|
122
131
|
| `rolemodel:turbo:form` | `dynamic-forms` |
|
|
123
132
|
| `rolemodel:soft_destroyable` | `soft-destroyable` |
|
|
124
|
-
| `rolemodel:core_setup` | `polymorphic-parent-resources`, `rake-tasks` |
|
|
133
|
+
| `rolemodel:core_setup` | `controller-patterns`, `polymorphic-parent-resources`, `rake-tasks` |
|
|
125
134
|
|
|
126
135
|
## Utilities
|
|
127
136
|
|
data/exe/rmr
ADDED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## What you get
|
|
6
6
|
|
|
7
|
+
* [Agent Docs](./agent_docs)
|
|
7
8
|
* [Editors](./editors)
|
|
8
9
|
* [Github](./github)
|
|
9
10
|
* [GoodJob](./good_job)
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
* [Kaminari](./kaminari)
|
|
12
13
|
* [Linters](./linters)
|
|
13
14
|
* [Lograge](./lograge)
|
|
15
|
+
* [Dotenv](./dotenv)
|
|
14
16
|
* [Mailers](./mailers)
|
|
15
17
|
* [Optics](./optics)
|
|
16
18
|
* [React](./react)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Agent Docs Generator
|
|
2
|
+
|
|
3
|
+
[USAGE](./USAGE)
|
|
4
|
+
|
|
5
|
+
The agent instructions and conventions a new RoleModel app starts with. `rolemodel:core_setup` runs it.
|
|
6
|
+
|
|
7
|
+
## What you get
|
|
8
|
+
|
|
9
|
+
- `AGENTS.md`, with `CLAUDE.md` pointing at it. Fill in its first sentence: what the app is, and the one fact that changes how every task in it is approached.
|
|
10
|
+
- `docs/CONVENTIONS.md`, an index of the files in `docs/conventions/`. Each entry carries a `<!-- paths: -->` glob naming the files it applies to.
|
|
11
|
+
- `.github/instructions/conventions.instructions.md`, which points Copilot (including code review) at the same conventions.
|
|
12
|
+
- `.claude/hooks/surface_conventions.rb`, registered in `.claude/settings.json`. Before Claude Code edits a file, the hook lists the conventions whose globs match it. It's downloaded from the [`scaffold-docs`](https://github.com/RoleModel/skills/tree/main/skills/scaffold-docs) skill, so there's one copy to maintain, and it needs Ruby on the `PATH`.
|
|
13
|
+
|
|
14
|
+
The conventions assume the stack `core_setup` installs (Slim, SimpleForm, Optics, Turbo, RSpec with Playwright) and the [`controller-patterns`](https://github.com/RoleModel/skills/tree/main/skills/controller-patterns) skill. For an existing app, use the `scaffold-docs` and `generate-conventions` skills instead.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Adds AGENTS.md and RoleModel's starting conventions for a new app
|
|
3
|
+
|
|
4
|
+
Writes AGENTS.md (with CLAUDE.md pointing at it), docs/CONVENTIONS.md and
|
|
5
|
+
the convention files it indexes, and Copilot instructions that point at
|
|
6
|
+
them. It also installs the surface_conventions hook from RoleModel/skills,
|
|
7
|
+
which shows Claude Code the conventions that apply to each file it edits.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
rails generate rolemodel:agent_docs
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Rolemodel
|
|
2
|
+
class AgentDocsGenerator < GeneratorBase
|
|
3
|
+
HOOK_URL = 'https://raw.githubusercontent.com/RoleModel/skills/main/skills/scaffold-docs/assets/surface_conventions.rb'.freeze
|
|
4
|
+
|
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
|
6
|
+
|
|
7
|
+
def install_docs
|
|
8
|
+
directory '.', '.'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def install_hook
|
|
12
|
+
get HOOK_URL, '.claude/hooks/surface_conventions.rb'
|
|
13
|
+
chmod '.claude/hooks/surface_conventions.rb', 0o755
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def project_name
|
|
19
|
+
Rails.application.class.module_parent_name.titleize
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/generators/rolemodel/agent_docs/templates/.github/instructions/conventions.instructions.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "app/**/*,spec/**/*,db/migrate/**/*,lib/**/*,config/**/*"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Conventions
|
|
6
|
+
|
|
7
|
+
`docs/CONVENTIONS.md` is the source of truth for this repo's conventions. Each entry carries a `<!-- paths: ... -->` comment naming the files it applies to. Read the convention files whose paths match what you're changing, and follow what they say — not the one-line index summary.
|
|
8
|
+
|
|
9
|
+
The branch name or PR title carries a ticket ID like `ABC-123`. Whenever the `linear` MCP server is connected, fetch that issue with `linear-get_issue` and read its description and acceptance criteria before writing or reviewing code — every time, not only when something looks off. Flag changes that contradict the ticket and requirements the diff doesn't address. No ID, or no server: work against these conventions alone and don't block on it.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# <%= project_name %>
|
|
2
|
+
|
|
3
|
+
<One sentence: what this app is, plus the one fact that changes how every task in it is approached.>
|
|
4
|
+
|
|
5
|
+
## How We Build
|
|
6
|
+
|
|
7
|
+
- Deliver the smallest change that adds value. Speculative complexity makes the next change harder, so never pre-solve a hypothetical case; flag real uncertainty in one line and move on.
|
|
8
|
+
- Make the change easy, then make the easy change. When extending something, ask whether it's still the right shape, and reshape it first if not.
|
|
9
|
+
- Think like a Rubyist: prefer polymorphism to conditionals, and Rails conventions to custom machinery.
|
|
10
|
+
- Fix root causes, never symptoms. When reusing a method exposes a bug, fix that method rather than writing a near-copy around it.
|
|
11
|
+
- Testability is a code virtue: write code that looks test-first even when it wasn't. Test behavior, not implementation, and don't over-constrain.
|
|
12
|
+
- Prefer a clearer name or an extracted method to a comment.
|
|
13
|
+
|
|
14
|
+
## Before Editing
|
|
15
|
+
|
|
16
|
+
- Read `docs/CONVENTIONS.md`, then the convention files relevant to the task.
|
|
17
|
+
- No new gems, top-level directories, base classes, or JS libraries without asking. If no existing pattern fits, stop and say so.
|
|
18
|
+
- Keep changes minimal and focused; preserve unrelated work in a dirty tree.
|
|
19
|
+
- Write a focused failing test before implementing feature behavior.
|
|
20
|
+
|
|
21
|
+
## Verification
|
|
22
|
+
|
|
23
|
+
- `bin/setup` once per checkout; `bin/dev` to run the app.
|
|
24
|
+
- `bundle exec rspec spec/path/to_spec.rb` for the specs your change touches. CI runs the full suite; don't run it locally.
|
|
25
|
+
- `bundle exec rubocop -a`
|
|
26
|
+
- `yarn eslint`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Conventions
|
|
2
|
+
|
|
3
|
+
Read the entries below, then the files relevant to the task.
|
|
4
|
+
|
|
5
|
+
- [Controllers follow the controller-patterns skill](conventions/controllers.md) — load the skill before writing a controller or route; no custom actions. <!-- paths: app/controllers/**/*.rb, config/routes.rb -->
|
|
6
|
+
- [Logic lives in models](conventions/logic-in-models.md) — models, POROs and form objects; app/services only for external boundaries; jobs call one method. <!-- paths: app/controllers/**/*.rb, app/jobs/**/*.rb, app/models/**/*.rb, app/forms/**/*.rb, app/services/**/*.rb -->
|
|
7
|
+
- [Callbacks stay guarded](conventions/callbacks.md) — the record, its siblings, or a Turbo refresh; guarded state-transition jobs; never mail or API calls. <!-- paths: app/models/**/*.rb -->
|
|
8
|
+
- [String-backed enums, referenced by key](conventions/string-enums.md) — explicit string values, never a magic string. <!-- paths: app/models/**/*.rb, db/migrate/*.rb, spec/factories/**/*.rb -->
|
|
9
|
+
- [Queries live in model scopes](conventions/reuse-scopes.md) — named scopes, no order/where/group_by in templates. <!-- paths: app/controllers/**/*.rb, app/jobs/**/*.rb, app/models/**/*.rb, app/views/**/*.slim -->
|
|
10
|
+
- [No SQL strings in queries](conventions/no-sql-strings.md) — hashes, ranges, association joins, in_order_of; Arel only as a last resort. <!-- paths: app/**/*.rb, lib/**/*.rb, spec/**/*.rb -->
|
|
11
|
+
- [Eager load in the query that feeds the view](conventions/eager-loading.md) — includes up front; includes plus joins becomes eager_load. <!-- paths: app/controllers/**/*.rb, app/models/**/*.rb, app/jobs/**/*.rb, app/views/**/*.slim -->
|
|
12
|
+
- [Views are Slim; forms are simple_form](conventions/views-and-forms.md) — Slim, simple_form and app/inputs, render records by to_partial_path, shared partials in app/views/application, Optics. <!-- paths: app/views/**/*.slim, app/inputs/**/*.rb, app/helpers/**/*.rb, app/assets/stylesheets/**/*.css -->
|
|
13
|
+
- [Partials declare their locals](conventions/partial-locals.md) — locals on the first line; never an instance variable. <!-- paths: app/views/**/_*.slim -->
|
|
14
|
+
- [Reach for Turbo before Stimulus](conventions/stimulus.md) — TurboForm and Turbo refreshes first; Stimulus only for browser-only interactions. <!-- paths: app/javascript/**/*.js, app/views/**/*.slim -->
|
|
15
|
+
- [Generate migrations; never renumber one](conventions/migrations.md) — generator timestamps, data__ migrations with their own models, schema.rb column order. <!-- paths: db/migrate/*.rb, db/schema.rb -->
|
|
16
|
+
- [Test layers](conventions/test-layers.md) — system specs for flows, request specs for page-less endpoints, no controller specs. <!-- paths: spec/**/*.rb -->
|
|
17
|
+
- [A fix ships with the spec that proves it](conventions/reproduce-the-bug.md) — failing-first specs with factories; don't stub the app's own models. <!-- paths: spec/**/*.rb -->
|
|
18
|
+
- [System specs assert what a user sees](conventions/system-spec-assertions.md) — labels and text for targets, data_test for scoping, flash for success. <!-- paths: spec/system/**/*.rb, app/views/**/*.slim -->
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Callbacks stay guarded
|
|
2
|
+
|
|
3
|
+
A callback derives the record's own attributes, keeps its siblings consistent, or broadcasts a Turbo refresh. It may enqueue a job for a specific state transition, but only behind a guard like `if: -> { saved_change_to_status?(to: 'closed') }`. A callback never sends mail or calls an external API directly.
|
|
4
|
+
|
|
5
|
+
An unguarded side effect runs on every save path, including factories, imports, and the console.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Eager load in the query that feeds the view
|
|
2
|
+
|
|
3
|
+
Load the associations a view or job walks with `includes` in the query that fetches the records, not with per-row lookups.
|
|
4
|
+
|
|
5
|
+
`includes` silently turns into one large joined `eager_load` when the same association is also joined or filtered on.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Logic lives in models
|
|
2
|
+
|
|
3
|
+
Put a business rule or state transition in a named model method, or in a PORO under `app/models/`. Put input spanning several records in a form object in `app/forms/` that includes `ActiveModel::Model` and `ActiveModel::Attributes`.
|
|
4
|
+
|
|
5
|
+
`app/services/` is for boundaries with the outside world (third-party APIs, uploads, webhook consumers). Don't add a service for domain logic.
|
|
6
|
+
|
|
7
|
+
A controller holds control flow only (see the controller-patterns skill). A job loads its records and calls one model method.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Generate migrations; never renumber one
|
|
2
|
+
|
|
3
|
+
Create a migration with `bin/rails generate migration`, never by hand-writing the timestamp: round `...0000` versions collide. The `schema_migrations` table tracks applied migrations by their timestamp prefix alone, so never change a committed migration's timestamp.
|
|
4
|
+
|
|
5
|
+
Generate a migration that changes data as `bin/rails generate migration data__<short_description>`, so data migrations stand apart from schema changes in `db/migrate/`. It declares its own models, so later changes to the app's models can't change what it does. Name each after its table and inherit from `ActiveRecord::Base`: `class Issue < ActiveRecord::Base; end`. A table with a `type` column also needs `self.inheritance_column = nil`. Back-fill with one `update_all` per distinct value rather than one per row.
|
|
6
|
+
|
|
7
|
+
`db/schema.rb` dumps columns in the local database's physical order. Before committing it, check that no column moved without a migration causing it; order follows the order migrations landed on the default branch.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# No SQL strings in queries
|
|
2
|
+
|
|
3
|
+
Build queries from ActiveRecord, never from SQL string fragments. That rules out `select('...')`, `order('...')`, `pluck('...')`, `joins('...')`, `group('...')`, `where('start_date < ?', date)`, string `update_all`, and `Arel.sql(...)`.
|
|
4
|
+
|
|
5
|
+
Use instead:
|
|
6
|
+
|
|
7
|
+
- Hash conditions and open-ended ranges: `where(start_date: ...date)`, `where(archived_at: nil)`.
|
|
8
|
+
- Association joins and nested hashes: `joins(:team).order(teams: { name: :asc })`.
|
|
9
|
+
- `in_order_of(:status, %w[active pending archived])` for a custom sort order.
|
|
10
|
+
|
|
11
|
+
If a query seems to need raw SQL (a JSONB `->>` lookup, Postgres `DISTINCT ON`, `NULLS LAST`), redesign it: store the value in a real column, or narrow the rows with a scope and pick in Ruby. An Arel node is the last resort, and worth a note in the PR.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Reach for Turbo before Stimulus
|
|
2
|
+
|
|
3
|
+
Dynamic page behavior is server-rendered: a dependent or conditional form uses TurboForm (the `dynamic-forms` skill), and a page that changes after an action redirects and morphs with a Turbo refresh. Stimulus is for interactions only the browser can do (drag-and-drop, Tom Select), using the controllers the gem's generators install. No inline JavaScript in templates. A new Stimulus controller is a question to raise in the PR.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# System specs assert what a user sees
|
|
2
|
+
|
|
3
|
+
Select by what the user sees, never by CSS class or DOM structure:
|
|
4
|
+
|
|
5
|
+
- Click targets and form fields by their visible text or label: `click_on "Yes, I'm Sure"`, `fill_in 'Name', with: 'Bob'`. A field without a label uses its name attribute: `fill_in 'user[name]', with: 'Bob'`.
|
|
6
|
+
- Scope to one part of the page with a `data-testid` from `dom_id`, and select it with the `data_test` helper:
|
|
7
|
+
|
|
8
|
+
```slim
|
|
9
|
+
tr data-testid=dom_id(widget)
|
|
10
|
+
td = link_to 'Edit', edit_widget_path(widget)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
within(data_test(widget)) { click_on 'Edit' }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
End every interaction with an assertion on its visible result. For a create, update or destroy, that's usually the flash message: `expect(page).to have_content 'Successfully Created Widget'`.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Test layers
|
|
2
|
+
|
|
3
|
+
Cover a user flow with a system spec on the default `rack_test` driver, and add `js: true` (Playwright) only when the behavior needs JavaScript. Cover an endpoint with no page of its own (a webhook, a turbo_stream or JSON endpoint) with a request spec in `spec/requests/`. Don't write controller specs. Unit-test logic in the model that holds it, and policies in `spec/policies/`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Views are Slim; forms are simple_form
|
|
2
|
+
|
|
3
|
+
Templates are Slim. Build every form with `simple_form_for`, `simple_fields_for` for nested attributes, and `f.association` for `belongs_to` selects. Reach for the custom inputs in `app/inputs/` before adding one.
|
|
4
|
+
|
|
5
|
+
Every input option earns its place: drop options that restate a default. A `label_method` repeated across forms becomes `to_label` on the model; an option every input of a type needs becomes a custom input or wrapper.
|
|
6
|
+
|
|
7
|
+
Render records with `render @widget` or `render @widgets`, which find the partial through `to_partial_path`. Name a partial only when no record owns it.
|
|
8
|
+
|
|
9
|
+
Shared partials live in `app/views/application/`, the fallback lookup path for a bare `render`, never in `app/views/shared/`. Check there and in `app/helpers/` for an existing partial or helper before writing a new one. Style with Optics classes and tokens (the `optics-context` skill), not one-off CSS.
|
|
@@ -3,6 +3,7 @@ module Rolemodel
|
|
|
3
3
|
source_root File.expand_path('templates', __dir__)
|
|
4
4
|
|
|
5
5
|
def run_all_the_generators
|
|
6
|
+
generate 'rolemodel:dotenv'
|
|
6
7
|
generate 'rolemodel:github'
|
|
7
8
|
generate 'rolemodel:heroku'
|
|
8
9
|
generate 'rolemodel:readme'
|
|
@@ -19,6 +20,7 @@ module Rolemodel
|
|
|
19
20
|
generate 'rolemodel:saas:all'
|
|
20
21
|
generate 'rolemodel:mailers'
|
|
21
22
|
generate 'rolemodel:linters:all'
|
|
23
|
+
generate 'rolemodel:agent_docs'
|
|
22
24
|
generate 'rolemodel:ui_components:all'
|
|
23
25
|
generate 'rolemodel:source_map'
|
|
24
26
|
generate 'rolemodel:good_job'
|
|
@@ -19,6 +19,7 @@ app you can push straight to Heroku right after generation.
|
|
|
19
19
|
|
|
20
20
|
## What you get
|
|
21
21
|
|
|
22
|
+
- [Dotenv](../dotenv) — local settings in `.env.local`, and `EnvValue` to read them
|
|
22
23
|
- [Slim](../slim) — Slim templates
|
|
23
24
|
- [Webpack](../webpack) — Webpack v5 for JS and CSS
|
|
24
25
|
- [Optics](../optics) — Optics design system and icons
|
|
@@ -30,9 +31,12 @@ app you can push straight to Heroku right after generation.
|
|
|
30
31
|
- [GitHub](../github) — standard GitHub configuration
|
|
31
32
|
- [Readme](../readme) — standard project README
|
|
32
33
|
- [Linters](../linters) — Rubocop and ESLint
|
|
34
|
+
- [Agent Docs](../agent_docs) — `AGENTS.md`, conventions, and the hook that surfaces them
|
|
33
35
|
- [Heroku](../heroku) — standard Heroku deployment configuration
|
|
34
36
|
- [Sentry](../sentry) — error monitoring for Ruby and JavaScript
|
|
35
37
|
- [Lograge](../lograge) — condensed request logging
|
|
38
|
+
- The [`controller-patterns`](https://github.com/RoleModel/skills/tree/main/skills/controller-patterns)
|
|
39
|
+
agent skill for RoleModel's controller shapes, installed into `.agents/skills`
|
|
36
40
|
- The [`polymorphic-parent-resources`](https://github.com/RoleModel/skills/tree/main/skills/polymorphic-parent-resources)
|
|
37
41
|
and [`rake-tasks`](https://github.com/RoleModel/skills/tree/main/skills/rake-tasks) agent skills for
|
|
38
42
|
`resource_for` and `Rolemodel::Utility::TaskTools`, installed into `.agents/skills`
|
|
@@ -2,10 +2,10 @@ Description:
|
|
|
2
2
|
Runs the core generators every new Rails app should have
|
|
3
3
|
|
|
4
4
|
Sets up Slim, Webpack, Optics, SimpleForm, Tom Select, testing (RSpec &
|
|
5
|
-
friends), Turbo, flash messages, GitHub config, README, linters,
|
|
6
|
-
deployment, Sentry, and Lograge. It also installs the agent skills for
|
|
7
|
-
resource_for and TaskTools. The result is an app
|
|
8
|
-
directly to Heroku.
|
|
5
|
+
friends), Turbo, flash messages, GitHub config, README, linters, agent
|
|
6
|
+
docs and conventions, Heroku deployment, Sentry, and Lograge. It also installs the agent skills for
|
|
7
|
+
controller patterns, resource_for, and TaskTools. The result is an app
|
|
8
|
+
that is ready to push directly to Heroku.
|
|
9
9
|
|
|
10
10
|
Pass an icon library flag (--material, --phosphor, --tabler, --feather,
|
|
11
11
|
--lucide, or --custom) to choose the Optics icons up front.
|
|
@@ -7,13 +7,15 @@ module Rolemodel
|
|
|
7
7
|
class_option :skip_deployable, type: :boolean, default: false, desc: 'skip generators for app deployment (Heroku, Sentry, Lograge)'
|
|
8
8
|
|
|
9
9
|
def install_agent_skills
|
|
10
|
-
say 'Installing agent skills
|
|
10
|
+
say 'Installing agent skills', :green
|
|
11
11
|
|
|
12
|
+
install_skill 'controller-patterns'
|
|
12
13
|
install_skill 'polymorphic-parent-resources'
|
|
13
14
|
install_skill 'rake-tasks'
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def run_the_core_generators
|
|
18
|
+
generate 'rolemodel:dotenv'
|
|
17
19
|
generate 'rolemodel:slim'
|
|
18
20
|
generate 'rolemodel:webpack'
|
|
19
21
|
generate 'rolemodel:optics:all', *icon_library_flags
|
|
@@ -25,6 +27,7 @@ module Rolemodel
|
|
|
25
27
|
generate 'rolemodel:github'
|
|
26
28
|
generate 'rolemodel:readme'
|
|
27
29
|
generate 'rolemodel:linters:all'
|
|
30
|
+
generate 'rolemodel:agent_docs'
|
|
28
31
|
return if options.skip_deployable?
|
|
29
32
|
|
|
30
33
|
generate 'rolemodel:heroku'
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Dotenv Generator
|
|
2
|
+
|
|
3
|
+
[USAGE](./USAGE)
|
|
4
|
+
|
|
5
|
+
Sets up local settings in a `.env.local` file, and adds `EnvValue` to read settings from ENV.
|
|
6
|
+
|
|
7
|
+
Run it with:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
bin/rails generate rolemodel:dotenv
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What you get
|
|
14
|
+
|
|
15
|
+
- The `dotenv` gem in the `development` and `test` groups.
|
|
16
|
+
- `/.env*` in `.gitignore`, so Git never commits your local values. New Rails apps already ignore it.
|
|
17
|
+
- `lib/env_value.rb`, required from `config/application.rb`.
|
|
18
|
+
- `spec/lib/env_value_spec.rb`, when the app has a `spec` folder.
|
|
19
|
+
|
|
20
|
+
## Put a local value in `.env.local`
|
|
21
|
+
|
|
22
|
+
Create `.env.local` in the project root. Add one `KEY=value` line for each setting:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
SENDGRID_API_KEY=xxxxxxxxx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Restart the server after you change the file.
|
|
29
|
+
|
|
30
|
+
To copy values from a Heroku app, run `heroku config -s -a <app>`. It prints `KEY=value` lines. Paste the lines you need into `.env.local`.
|
|
31
|
+
|
|
32
|
+
The dotenv gem loads `.env.local` in development. Tests don't read `.env.local`, so a test run never depends on your machine. Put a value that tests need in `.env.test`, or give it a `local:` or `default:` value (see [Defaults for each environment](#defaults-for-each-environment)). Production reads its values from the host, for example Heroku config vars.
|
|
33
|
+
|
|
34
|
+
## Read a setting with `EnvValue`
|
|
35
|
+
|
|
36
|
+
`EnvValue` reads a value from ENV. A blank value counts as unset. When the value is unset, `EnvValue` uses a default.
|
|
37
|
+
|
|
38
|
+
Read each setting once in `config/application.rb`, and keep it as a `config.x` value:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
config.x.sendgrid.api_key = EnvValue.string('SENDGRID_API_KEY')
|
|
42
|
+
config.x.report_emails = EnvValue.array('REPORT_EMAILS', default: %w[team@example.com])
|
|
43
|
+
config.x.serve_static_files = EnvValue.boolean('RAILS_SERVE_STATIC_FILES')
|
|
44
|
+
config.x.default_url = EnvValue.url('DEFAULT_URL', default: 'http://localhost:3000')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then read it in app code:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
Rails.configuration.x.sendgrid.api_key
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Method | Returns | When unset, with no default | When the value is not valid |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| `string` | the text | `nil` | — |
|
|
56
|
+
| `string!` | the text | raises | raises when blank |
|
|
57
|
+
| `array` | the comma-separated items, trimmed | `[]` | — |
|
|
58
|
+
| `boolean` | `true` for `true`, `t`, `1`, `yes`, `y`, `on`, `enabled`. `false` for `false`, `f`, `0`, `no`, `n`, `off`, `disabled`. Case does not matter. | `false` | raises on any other text, naming the key |
|
|
59
|
+
| `url` | the URL | `nil` | raises when it has no scheme or host |
|
|
60
|
+
|
|
61
|
+
Read settings in `config/application.rb`, so a raise stops the app when it starts. Then you see a bad value at once.
|
|
62
|
+
|
|
63
|
+
### Defaults for each environment
|
|
64
|
+
|
|
65
|
+
A default can be different in each environment. `EnvValue` uses the first of these that applies:
|
|
66
|
+
|
|
67
|
+
1. A key named for the current environment, such as `production:` or `staging:`. A key set to `nil` counts, and gives `nil`.
|
|
68
|
+
2. `local:`, in development and test only.
|
|
69
|
+
3. A block.
|
|
70
|
+
4. `default:`.
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
# Every environment except production falls back to dev-key. Staging gets dev-key too.
|
|
74
|
+
# Production gets nil unless ENCRYPTION_KEY is set.
|
|
75
|
+
EnvValue.string('ENCRYPTION_KEY', default: 'dev-key', production: nil)
|
|
76
|
+
|
|
77
|
+
# Only development and test fall back to dev-client-id. Staging and production get nil.
|
|
78
|
+
EnvValue.string('API_CLIENT_ID', local: 'dev-client-id')
|
|
79
|
+
|
|
80
|
+
# The block runs only when the key is unset.
|
|
81
|
+
EnvValue.url('DEFAULT_URL') { "https://#{EnvValue.string('HEROKU_APP_NAME')}.herokuapp.com" }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Move from `env.rb`
|
|
85
|
+
|
|
86
|
+
Some RoleModel apps keep local settings in `env.rb` and `.env_overrides.rb`. Those are Ruby files, so only Ruby can read them. A `.env` file holds plain `KEY=value` lines that Ruby, Node, Docker Compose, foreman and 1Password can all read.
|
|
87
|
+
|
|
88
|
+
If the app has `env.rb` or `.env_overrides.rb`:
|
|
89
|
+
|
|
90
|
+
1. Run the generator.
|
|
91
|
+
2. Move each `ENV['KEY'] ||= 'value'` line from `env.rb` and `.env_overrides.rb` to `.env.local` as `KEY=value`.
|
|
92
|
+
3. If `env.rb` set a value that production uses, add it as a default in `config/application.rb` with `EnvValue`.
|
|
93
|
+
4. Remove the line that requires `env.rb` from `config/application.rb`.
|
|
94
|
+
5. Delete `env.rb` and `.env_overrides.rb`.
|
|
95
|
+
|
|
96
|
+
## Generators that add settings
|
|
97
|
+
|
|
98
|
+
These generators add their settings to `config/application.rb` with `EnvValue`. If the app has no `lib/env_value.rb`, they run this generator first.
|
|
99
|
+
|
|
100
|
+
| Generator | ENV key | Setting |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| `rolemodel:heroku` | `LOG_LEVEL` | `config.x.log_level` (default `INFO`) |
|
|
103
|
+
| `rolemodel:sentry` | `SENTRY_DSN` | `config.x.sentry.dsn` |
|
|
104
|
+
| `rolemodel:mailers` | `WHITELISTED_EMAILS` | `config.x.whitelisted_emails` |
|
|
105
|
+
| | `DEFAULT_URL` | `config.x.default_url`: the app's full URL, such as `https://app.example.com`, used for links and assets in emails. Set it in production. Without it, a Heroku review app uses `https://<HEROKU_APP_NAME>.herokuapp.com`, and development uses `http://localhost:3000`. It replaces `PRODUCTION_HOST` and `REVIEW_APP`. The generator comments out the `default_url_options` line in development.rb and production.rb, so set the URL here, not there. |
|
|
106
|
+
| | `HEROKU_APP_NAME` | `config.x.heroku_app_name` |
|
|
107
|
+
| | `SENDGRID_API_KEY` | `config.x.sendgrid.api_key` |
|
|
108
|
+
| `rolemodel:saas:devise` | `DEFAULT_URL` | `config.x.default_url`, the same setting as `rolemodel:mailers` |
|
|
109
|
+
| `rolemodel:source_map` | `SOURCE_MAPS_ALLOWED_USERS_EMAILS` | `config.x.source_maps.allowed_user_emails` |
|
|
110
|
+
| `rolemodel:good_job` | `GOOD_JOB_QUEUES` | `config.x.good_job.queues` (default `pdf:1;-pdf`) |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Loads local settings from a .env.local file with the dotenv gem,
|
|
3
|
+
and adds EnvValue to read typed settings from ENV.
|
|
4
|
+
|
|
5
|
+
Example:
|
|
6
|
+
rails generate rolemodel:dotenv
|
|
7
|
+
|
|
8
|
+
This will create:
|
|
9
|
+
lib/env_value.rb
|
|
10
|
+
spec/lib/env_value_spec.rb (when the app has a spec folder)
|
|
11
|
+
|
|
12
|
+
This will change:
|
|
13
|
+
Gemfile (adds dotenv to the development and test groups)
|
|
14
|
+
config/application.rb (requires lib/env_value)
|
|
15
|
+
.gitignore (ignores /.env*)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rolemodel
|
|
4
|
+
class DotenvGenerator < GeneratorBase
|
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
|
6
|
+
|
|
7
|
+
def install_dotenv
|
|
8
|
+
say 'Installing dotenv', :green
|
|
9
|
+
|
|
10
|
+
bundle_command('add dotenv --group "development, test"')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# New Rails apps already ignore /.env*. Older apps may not.
|
|
14
|
+
def ignore_env_files
|
|
15
|
+
gitignore = File.join(destination_root, '.gitignore')
|
|
16
|
+
content = File.exist?(gitignore) ? File.read(gitignore) : ''
|
|
17
|
+
return if content.include?('/.env*')
|
|
18
|
+
|
|
19
|
+
create_file '.gitignore', content + <<~IGNORE, force: true
|
|
20
|
+
|
|
21
|
+
# Ignore all environment files.
|
|
22
|
+
/.env*
|
|
23
|
+
IGNORE
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_env_value
|
|
27
|
+
say 'Adding EnvValue to read settings from ENV', :green
|
|
28
|
+
|
|
29
|
+
copy_file 'lib/env_value.rb'
|
|
30
|
+
inject_into_file(
|
|
31
|
+
'config/application.rb',
|
|
32
|
+
"require_relative '../lib/env_value'\n",
|
|
33
|
+
before: /^# Require the gems listed in Gemfile/
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def add_env_value_spec
|
|
38
|
+
return unless Dir.exist?(File.join(destination_root, 'spec'))
|
|
39
|
+
|
|
40
|
+
copy_file 'spec/lib/env_value_spec.rb'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|