tarquinn 0.4.0 → 1.0.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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +22 -8
  3. data/.claude/agents/architect.md +45 -0
  4. data/.claude/agents/ruby.md +39 -0
  5. data/.claude/scripts/check_ruby.sh +8 -0
  6. data/.github/commit_message_template-2.0.md +32 -0
  7. data/.github/commit_message_template.md +10 -0
  8. data/.github/copilot-instructions.md +1 -188
  9. data/.github/pull_request_template.md +17 -0
  10. data/.github/tarquinn-usage.md +152 -0
  11. data/.gitignore +1 -0
  12. data/AGENTS.md +221 -0
  13. data/CLAUDE.md +1 -0
  14. data/Dockerfile +2 -2
  15. data/Gemfile +13 -12
  16. data/README.md +34 -6
  17. data/docs/agents/arcanum-split-issue.md +9 -0
  18. data/docs/agents/architecture.md +20 -0
  19. data/docs/agents/contributing.md +150 -0
  20. data/docs/agents/flow.md +5 -0
  21. data/docs/agents/folder-structure.md +14 -0
  22. data/docs/agents/issue-enhancement.md +10 -0
  23. data/docs/agents/issues/.gitkeep +1 -0
  24. data/docs/agents/plans/.gitkeep +1 -0
  25. data/lib/tarquinn/class_methods.rb +3 -3
  26. data/lib/tarquinn/controller.rb +17 -0
  27. data/lib/tarquinn/redirection_config/options.rb +6 -27
  28. data/lib/tarquinn/redirection_config.rb +4 -20
  29. data/lib/tarquinn/redirection_handler.rb +49 -31
  30. data/lib/tarquinn/version.rb +1 -1
  31. data/scripts/bump_version.sh +62 -0
  32. data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +6 -2
  33. data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +1 -1
  34. data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
  35. data/spec/dummy/config/initializers/inflections.rb +1 -0
  36. data/spec/dummy/config/initializers/permissions_policy.rb +1 -0
  37. data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -5
  38. data/spec/lib/tarquinn/controller_spec.rb +20 -0
  39. data/spec/lib/tarquinn/redirection_config/options_spec.rb +10 -24
  40. data/spec/lib/tarquinn/redirection_handler_spec.rb +40 -5
  41. data/spec/lib/tarquinn_spec.rb +33 -3
  42. data/spec/spec_helper.rb +6 -0
  43. data/tarquinn.gemspec +2 -2
  44. metadata +27 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 472e75e26a2d619f0284c9eb797c5e47f717a9f9a6e52757fc1c5ad7272a174f
4
- data.tar.gz: efb31ef0021491a3b99c48cb8c3a34026493a10500636449195c1070d281dc91
3
+ metadata.gz: 014c2593fc9f17f40c8ff0ce2ecbe458b059c8fd6d13a0a3868a0154e3789e1b
4
+ data.tar.gz: 7e79e0b89f7976970993cf72a3423925d997bd9666b540111531b95c77575b0a
5
5
  SHA512:
6
- metadata.gz: 9391c038495ea739fee48b43a9c104bcb0dfb887aa87ecb75be3d1378ee2c11649cc68725fd8beea215036065b5deb1aeca08babea956d77b42628b887ead261
7
- data.tar.gz: 59ccde1cade0e2b76b82f89073409cf9ced274d7346214ae08f2d4e6f06e11269feb9b768c219064bcec0e748205c1ce6a5eb45515e21dbe404a53459cb6643b
6
+ metadata.gz: cb17421cd3444b64b0c742dfaec31cddd0c5c97036238fae21f59d91b369d5c81a36616bd248575b6f7458745be8809674b89004564014af16c367c718ab9770
7
+ data.tar.gz: b8b1f54c0981fcd7ee1cc15e4ed87ab1344f82835f511054f6db184943d55fa5e406d3ba9f92d60120c3742f181d024fe00709b2bc16a4f2313b8c43afe58632
data/.circleci/config.yml CHANGED
@@ -1,6 +1,5 @@
1
- version: 2
1
+ version: 2.1
2
2
  workflows:
3
- version: 2
4
3
  test-and-build:
5
4
  jobs:
6
5
  - test:
@@ -11,18 +10,23 @@ workflows:
11
10
  filters:
12
11
  tags:
13
12
  only: /.*/
13
+ - coverage-final:
14
+ requires: [test]
15
+ filters:
16
+ tags:
17
+ only: /.*/
14
18
  - build-and-release:
15
- requires: [test, checks]
19
+ requires: [test, checks, coverage-final]
16
20
  filters:
17
21
  tags:
18
22
  only: /\d+\.\d+\.\d+/
19
23
  branches:
20
24
  only:
21
- - main
25
+ - master
22
26
  jobs:
23
27
  test:
24
28
  docker:
25
- - image: darthjee/circleci_ruby_331:1.0.1
29
+ - image: darthjee/circleci_ruby_3412:1.0.0
26
30
  environment:
27
31
  PROJECT: tarquinn
28
32
  steps:
@@ -32,10 +36,20 @@ jobs:
32
36
  command: bundle install
33
37
  - run:
34
38
  name: RSpec
35
- command: bundle exec rspec
39
+ command: CI=true bundle exec rspec
40
+ - run:
41
+ name: Upload coverage to Codacy (partial)
42
+ command: bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial -r coverage/lcov/project.lcov
43
+ coverage-final:
44
+ docker:
45
+ - image: darthjee/circleci_ruby_3412:1.0.0
46
+ steps:
47
+ - run:
48
+ name: Finalize coverage on Codacy
49
+ command: bash <(curl -Ls https://coverage.codacy.com/get.sh) final
36
50
  checks:
37
51
  docker:
38
- - image: darthjee/circleci_ruby_331:1.0.1
52
+ - image: darthjee/circleci_ruby_3412:1.0.0
39
53
  environment:
40
54
  PROJECT: tarquinn
41
55
  steps:
@@ -60,7 +74,7 @@ jobs:
60
74
  command: check_specs
61
75
  build-and-release:
62
76
  docker:
63
- - image: darthjee/circleci_ruby_331:1.0.1
77
+ - image: darthjee/circleci_ruby_3412:1.0.0
64
78
  environment:
65
79
  PROJECT: tarquinn
66
80
  steps:
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: architect
3
+ description: Tarquinn architect and coordinator. Use for cross-cutting tasks, multi-agent coordination, documentation, root-level files, or any task that spans more than one agent's scope.
4
+ tools: Read, Edit, Write, Bash, Agent
5
+ ---
6
+
7
+ You are the architect and coordinator for the Tarquinn project — a Ruby gem providing generic redirection control for Rails controllers.
8
+
9
+ ## Your scope
10
+
11
+ - `docs/agents/` — all project documentation
12
+ - Root-level files: `README.md`, `AGENTS.md`, `CLAUDE.md`, `.github/`, `.circleci/`, `Dockerfile`, `docker-compose.yml`, `Makefile`, gemspec
13
+ - Cross-cutting decisions that span multiple layers
14
+ - Coordination of the other specialist agents
15
+
16
+ ## Specialist agents
17
+
18
+ Delegate implementation, exploration, and planning work to the right agent. Never implement, explore, or plan what belongs to a specialist yourself.
19
+
20
+ | Agent | Scope |
21
+ |-------|-------|
22
+ | `ruby` | `lib/`, `spec/`, `config/` — gem source, specs and quality-tool configs |
23
+
24
+ ## How to coordinate
25
+
26
+ When a task spans multiple agents:
27
+
28
+ 1. **Break it down** — identify which parts belong to which agent.
29
+ 2. **Delegate exploration first** — dispatch the specialist whose scope covers the relevant area rather than reading the code yourself.
30
+ 3. **Sequence or parallelize** — run independent work in parallel; sequence dependent work.
31
+ 4. **Integrate** — after specialists finish, verify cross-cutting concerns.
32
+ 5. **Update docs** — reflect any architectural change in `docs/agents/`.
33
+
34
+ ## Documentation (`docs/agents/`)
35
+
36
+ | File | Contents |
37
+ |------|----------|
38
+ | [Folder Structure](../../docs/agents/folder-structure.md) | Top-level directory layout and the role of each folder. |
39
+ | [Architecture](../../docs/agents/architecture.md) | Source layout and modules. |
40
+ | [Contributing](../../docs/agents/contributing.md) | Commit, PR and code organization rules. |
41
+ | [Flow](../../docs/agents/flow.md) | Main runtime flow of the application. |
42
+ | [Plans](../../docs/agents/plans/) | Implementation plans. |
43
+ | [Issues](../../docs/agents/issues/) | Detailed specs for open issues. |
44
+
45
+ Keep documentation up to date after any architectural change. When a new agent is created or its scope changes, update this file and `AGENTS.md`.
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: ruby
3
+ description: Tarquinn ruby specialist. Use for any task involving Ruby code, RSpec specs, Rubocop, Yardstick or quality-tool configs in lib/, spec/ and config/.
4
+ tools: Read, Edit, Write, Bash
5
+ ---
6
+
7
+ You are the ruby specialist for the Tarquinn project — a Ruby gem providing generic redirection control for Rails controllers.
8
+
9
+ ## Your scope
10
+
11
+ You own everything inside:
12
+
13
+ - `lib/` — gem source (`tarquinn.rb` concern and `tarquinn/` internals)
14
+ - `spec/` — RSpec suite, shared examples and the Rails `dummy/` app
15
+ - `config/` — check_specs, rubycritic and yardstick configs
16
+
17
+ Do NOT touch `docs/agents/`, root-level files (`README.md`, `AGENTS.md`, `CLAUDE.md`, `.github/`, `.circleci/`) or anything outside the folders above.
18
+
19
+ ## Stack
20
+
21
+ - Ruby, `ActiveSupport::Concern`, Rails (dummy app for integration specs)
22
+ - RSpec, Rubocop, Yardstick (YARD coverage), RubyCritic
23
+
24
+ ## Commands
25
+
26
+ ```bash
27
+ bundle exec rspec
28
+ rubocop
29
+ bundle exec rake verify_measurements
30
+ check_specs
31
+ ```
32
+
33
+ ## Conventions
34
+
35
+ - Follow `docs/agents/contributing.md` and the code style in `AGENTS.md`.
36
+ - snake_case file names; specs mirror the source path under `spec/lib/`.
37
+ - Public methods before private ones; classes receive dependencies via the constructor.
38
+ - Add YARD docs (`@param`, `@return`, `@api public`/`@api private`) to all public classes and methods.
39
+ - One behaviour per spec example; reusable `let` definitions.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ set -x
4
+
5
+ bundle exec rspec
6
+ rubocop
7
+ bundle exec rake verify_measurements
8
+ check_specs
@@ -0,0 +1,32 @@
1
+ ```text
2
+ <type>(<scope>): <subject> (issue #<id>)
3
+
4
+ <optional body: what was done and why, if not obvious>
5
+
6
+ Addresses-Comment: <optional: URL of the PR comment this commit addresses>
7
+
8
+ Co-Authored-By: <AI model name> <AI model email>
9
+ Co-Authored-By: <agent> agent <agent email>
10
+ ```
11
+
12
+ Note: unlike the model line above (always the running AI model's own
13
+ canonical noreply address), the agent line's email is independently
14
+ configurable per agent via the "git.email" key (a template such as
15
+ "you+{agent}@example.com", with "{agent}" substituted for the actual
16
+ agent name, e.g. "architect" or "backend") in
17
+ .claude/state/arcanum-config.json (local) or
18
+ .claude/configuration/arcanum-repo-config.json (repo) — see
19
+ docs/guides/arcanum-repo-config.md. When "git.email" is unset, the agent
20
+ line falls back to the same address as the model line, reproducing the
21
+ old, single-shared-email template's output.
22
+
23
+ The model line above can be omitted entirely by setting the
24
+ "git.omit_model_coauthor" key to "true" in the same three locations
25
+ (local state, repo config, or global config — see
26
+ docs/guides/arcanum-repo-config.md) — the agent line is always still
27
+ emitted regardless of this setting.
28
+
29
+ This file's mere presence (as "commit_message_template-2.0.md", not its
30
+ content) is what switches the commit scripts onto this new, two-distinct-
31
+ email behavior — the content itself is never parsed at runtime, it is
32
+ purely human-facing documentation of the shape above.
@@ -0,0 +1,10 @@
1
+ ```text
2
+ <type>(<scope>): <subject> (issue #<id>)
3
+
4
+ <optional body: what was done and why, if not obvious>
5
+
6
+ Addresses-Comment: <optional: URL of the PR comment this commit addresses>
7
+
8
+ Co-Authored-By: <AI model name> <AI model email>
9
+ Co-Authored-By: <agent> agent <AI model email>
10
+ ```
@@ -1,188 +1 @@
1
- # GitHub Copilot Instructions for Tarquinn
2
-
3
- ## Project Overview
4
-
5
- Tarquinn is a Ruby gem that provides generic redirection control for Rails controllers.
6
- It is implemented as an `ActiveSupport::Concern` that adds `before_action` hooks and
7
- class-level DSL methods (`redirection_rule`, `skip_redirection`, `skip_redirection_rule`)
8
- to any Rails controller.
9
-
10
- Key components:
11
-
12
- - **`Tarquinn`** – The main concern included in controllers; sets up `before_action :perform_redirection`.
13
- - **`Tarquinn::ClassMethods`** – DSL methods added to controller classes.
14
- - **`Tarquinn::RequestHandlerBuilder`** – Accumulates redirection configurations for a controller class.
15
- - **`Tarquinn::RequestHandler`** – Processes a single request, iterating over configs to find the first matching redirect.
16
- - **`Tarquinn::RedirectionHandler`** – Evaluates one redirection config (conditions + skip rules) for a request.
17
- - **`Tarquinn::RedirectionConfig`** – Holds the data for a single redirection rule (blocks, skip blocks, redirect target).
18
- - **`Tarquinn::Condition`** – Wraps a single condition (method name or block) used in redirection/skip evaluation.
19
- - **`Tarquinn::Controller`** – Thin wrapper around the Rails controller instance, used by handlers.
20
-
21
- ## Redirection Rules Data Flow
22
-
23
- ### How It Works
24
-
25
- 1. A controller includes `Tarquinn` (an `ActiveSupport::Concern`), which:
26
- - Extends the controller with `Tarquinn::ClassMethods`, making the DSL methods available.
27
- - Registers a `before_action :perform_redirection` that runs on every request.
28
-
29
- 2. During a request, `perform_redirection` delegates to `Tarquinn::RequestHandler`, which
30
- iterates over all registered `Tarquinn::RedirectionConfig` objects (in definition order)
31
- and applies the **first** rule whose conditions are satisfied.
32
-
33
- 3. Each rule is evaluated by `Tarquinn::RedirectionHandler`:
34
- - All condition methods and/or the optional block are evaluated against the current
35
- controller instance.
36
- - If **any** condition returns a truthy value the rule fires and the controller redirects
37
- to the path returned by the rule's target method.
38
- - Skip conditions (registered via `skip_redirection` or `skip_redirection_rule`) are
39
- checked first; if any skip condition is truthy the rule is bypassed entirely.
40
-
41
- ### Defining a Redirection Rule — `redirection_rule`
42
-
43
- ```ruby
44
- redirection_rule <rule_name>, *<condition_methods>, &<block>
45
- ```
46
-
47
- | Argument | Description |
48
- |---------------------|----------------------------------------------------------------------------------------------|
49
- | `rule_name` | Symbol. Also the name of the controller method that returns the redirect path. |
50
- | `condition_methods` | Zero or more symbol method names. Each is called on the controller; truthy → rule fires. |
51
- | `block` | Optional. Evaluated in the context of the controller; truthy → rule fires. |
52
-
53
- **Evaluation**: the rule fires when **any** condition method **or** the block returns truthy.
54
-
55
- #### Example 1 — block-based rule
56
-
57
- ```ruby
58
- redirection_rule :redirect_home { params[:secret_key] != '12345' }
59
-
60
- def redirect_home
61
- home_path
62
- end
63
- ```
64
-
65
- Redirects to `home_path` if `secret_key` is absent or different from `'12345'`.
66
-
67
- #### Example 2 — method-based rule
68
-
69
- ```ruby
70
- redirection_rule :redirect_home, :misses_secret_key
71
-
72
- def redirect_home
73
- home_path
74
- end
75
-
76
- def misses_secret_key
77
- params[:secret_key] != '12345'
78
- end
79
- ```
80
-
81
- Same behaviour as Example 1, but the condition is extracted into a dedicated method.
82
-
83
- ### Skipping a Rule for Specific Actions — `skip_redirection`
84
-
85
- ```ruby
86
- skip_redirection <rule_name>, *<actions>
87
- ```
88
-
89
- Prevents the named rule from running for the listed controller actions.
90
-
91
- ```ruby
92
- skip_redirection :redirect_home, :index
93
- ```
94
-
95
- The `index` action is not affected by the `redirect_home` rule; all other actions still are.
96
-
97
- ### Skipping a Rule Under a Condition — `skip_redirection_rule`
98
-
99
- ```ruby
100
- skip_redirection_rule <rule_name>, *<condition_methods>, &<block>
101
- ```
102
-
103
- Registers a skip condition for a rule. When the condition is truthy the rule is bypassed,
104
- regardless of the action.
105
-
106
- ```ruby
107
- skip_redirection_rule :redirect_home { params[:admin_key] == '9999' }
108
- ```
109
-
110
- The `redirect_home` rule does not fire when the correct admin key is provided.
111
-
112
- ### Passing Options to Redirection Rules
113
-
114
- You can pass options to `redirection_rule` to control advanced behavior. Currently, the main supported option is `domain`, which enables cross-domain redirection.
115
-
116
- | Option | Description |
117
- |----------|---------------------------------------------------------------------------------------------|
118
- | `domain` | String. If set, allows redirection to the specified domain (cross-domain). If not set, only same-host redirection is allowed. |
119
-
120
- #### Example — domain-based rule
121
-
122
- ```ruby
123
- redirection_rule :redirect_external, domain: 'example.com' do
124
- params[:should_redirect]
125
- end
126
-
127
- def redirect_external
128
- '/external_path'
129
- end
130
- ```
131
-
132
- This will only allow redirection to `https://example.com/external_path` because the domain option is set to `'example.com'`.
133
-
134
- ## Language
135
-
136
- All code, comments, documentation, commit messages, and PR descriptions must be written in **English**.
137
-
138
- ## Coding Standards
139
-
140
- ### General Style
141
-
142
- - Follow the existing RuboCop configuration (`.rubocop.yml` / `.rubocop_todo.yml`).
143
- - Use `# frozen_string_literal: true` at the top of every Ruby file.
144
- - Keep methods small and focused (Sandi Metz style): aim for methods under 5 lines.
145
- - Keep classes small with clear, single responsibilities and explicit object boundaries.
146
- - Avoid deeply nested conditionals; extract guard clauses or helper methods.
147
- - Use `private` / `attr_reader` to hide implementation details.
148
- - Use `delegate` (ActiveSupport) instead of manual forwarding where it improves readability.
149
-
150
- ### Documentation
151
-
152
- - Add **YARD** documentation to all public classes, modules, and methods.
153
- - Non-obvious private methods should also have short YARD comments.
154
- - Always include `@param`, `@return`, and `@api public` / `@api private` tags where applicable.
155
- - Ensure documentation coverage stays at or above the threshold in `config/yardstick.yml`.
156
-
157
- ### Tests
158
-
159
- - Write **RSpec** tests using the patterns established in `spec/`.
160
- - Keep tests small and focused — one behaviour per example.
161
- - Use `let` definitions that are **reusable** and **avoid duplication** across contexts.
162
- - Prefer `context` blocks to describe different input/state scenarios.
163
- - Avoid `before` blocks that do more than one thing; split them if needed.
164
- - Use `shared_examples` or `shared_context` when the same setup appears in multiple groups.
165
-
166
- ## CI Checks
167
-
168
- The CI pipeline (`.circleci/config.yml`) runs the following checks on every push.
169
- Reproduce them locally before opening a PR:
170
-
171
- | CI Step | Local Command |
172
- |-------------------------------|--------------------------------------------------|
173
- | Run tests | `bundle exec rspec` |
174
- | RuboCop lint | `bundle exec rubocop` |
175
- | YARD documentation coverage | `bundle exec rake verify_measurements` |
176
- | RubyCritic quality check | `rubycritic.sh` (or `bundle exec rubycritic`) |
177
-
178
- All checks must pass before a PR can be merged.
179
-
180
- ## Docker / Local Development
181
-
182
- To run the project locally, use the Makefile targets:
183
-
184
- - Build Docker image: `make build`
185
- - Start development environment: `make dev`
186
- - Run tests: `make tests`
187
-
188
- See the [Developer Guide](../README.md#developer-guide) in the README for further instructions.
1
+ See [AGENTS.md](../AGENTS.md) for project instructions.
@@ -0,0 +1,17 @@
1
+ ## Summary
2
+
3
+ <!-- One sentence describing what this PR does -->
4
+
5
+ ## Problem
6
+
7
+ <!-- What problem does this solve? Why is this change needed? -->
8
+
9
+ ## Solution
10
+
11
+ <!-- How was the problem solved? What approach was taken? -->
12
+
13
+ ## Details
14
+
15
+ <!-- Optional: implementation notes, migration steps, caveats. Remove this section if not needed. -->
16
+
17
+ Fixes #
@@ -0,0 +1,152 @@
1
+ # Tarquinn Usage Guide
2
+
3
+ Tarquinn is a Rails concern for managing controller redirections declaratively. It lets you
4
+ define redirection rules with conditions and skip rules directly in your controller classes.
5
+
6
+ ## Basic Setup
7
+
8
+ Add Tarquinn to your `Gemfile` and run `bundle install`:
9
+
10
+ ```ruby
11
+ gem 'tarquinn'
12
+ ```
13
+
14
+ Include `Tarquinn` in your base controller:
15
+
16
+ ```ruby
17
+ class ApplicationController < ActionController::Base
18
+ include Tarquinn
19
+ end
20
+ ```
21
+
22
+ ## Core Features
23
+
24
+ ### Redirection Rules
25
+
26
+ Use `redirection_rule` to declare a redirect. The first argument is both the rule name and
27
+ the name of the controller method that returns the redirect path. Additional arguments are
28
+ condition method names — the rule fires when **any** condition returns truthy.
29
+
30
+ ```ruby
31
+ class BaseController < ApplicationController
32
+ redirection_rule :redirect_login, :loggin_needed?
33
+
34
+ private
35
+
36
+ def redirect_login
37
+ login_path
38
+ end
39
+
40
+ def loggin_needed?
41
+ user.nil?
42
+ end
43
+ end
44
+ ```
45
+
46
+ ### Skip Redirection Rules
47
+
48
+ Use `skip_redirection_rule` in a child controller to prevent a rule from firing when a
49
+ condition is truthy:
50
+
51
+ ```ruby
52
+ class StaticController < BaseController
53
+ skip_redirection_rule :redirect_login, :is_home?
54
+
55
+ private
56
+
57
+ def is_home?
58
+ params[:action] == 'home'
59
+ end
60
+ end
61
+ ```
62
+
63
+ Use `skip_redirection` to bypass a rule for specific actions:
64
+
65
+ ```ruby
66
+ class StaticController < BaseController
67
+ skip_redirection :redirect_login, :index
68
+ end
69
+ ```
70
+
71
+ ### Block Syntax
72
+
73
+ Conditions can also be defined inline using a block:
74
+
75
+ ```ruby
76
+ redirection_rule :redirect_login do
77
+ user.nil?
78
+ end
79
+ ```
80
+
81
+ ## Advanced Features
82
+
83
+ ### Cross-Domain Redirection
84
+
85
+ Use the `domain:` option to redirect to an external domain.
86
+
87
+ **Static domain (String):**
88
+
89
+ ```ruby
90
+ class ExternalRedirectController < ApplicationController
91
+ redirection_rule :redirect_external, domain: 'example.com' do
92
+ params[:should_redirect]
93
+ end
94
+
95
+ private
96
+
97
+ def redirect_external
98
+ '/external_path'
99
+ end
100
+ end
101
+ ```
102
+
103
+ **Dynamic domain (Symbol):** the named method is called on the controller at request time to
104
+ resolve the domain:
105
+
106
+ ```ruby
107
+ class ExternalRedirectController < ApplicationController
108
+ redirection_rule :redirect_external, domain: :current_domain do
109
+ params[:should_redirect]
110
+ end
111
+
112
+ private
113
+
114
+ def redirect_external
115
+ '/external_path'
116
+ end
117
+
118
+ def current_domain
119
+ request.subdomain == 'admin' ? 'admin.example.com' : 'example.com'
120
+ end
121
+ end
122
+ ```
123
+
124
+ When `domain:` is not set, only same-host redirection is allowed.
125
+
126
+ ## How It Works
127
+
128
+ 1. Including `Tarquinn` automatically registers `before_action :perform_redirection`.
129
+ 2. On each request, skip conditions are evaluated first — if any is truthy the rule is
130
+ bypassed entirely.
131
+ 3. Redirect conditions are then evaluated; the rule fires when any condition returns truthy.
132
+ 4. Rules are evaluated in definition order; the **first** matching rule triggers the redirect.
133
+
134
+ ## Best Practices
135
+
136
+ - Define redirection rules in base controllers so child controllers inherit them.
137
+ - Use `skip_redirection_rule` or `skip_redirection` in child controllers to override
138
+ inherited rules.
139
+ - Keep redirect path methods private.
140
+ - Keep condition methods private and focused on a single responsibility.
141
+ - Name methods descriptively (e.g., `loggin_needed?`, `is_home?`).
142
+ - Use blocks for simple inline conditions.
143
+ - Use method symbols for conditions that are reused or need to be tested independently.
144
+
145
+ ## Common Use Cases
146
+
147
+ - **Login redirects** — redirect unauthenticated users to the login page.
148
+ - **Authorization redirects** — redirect unauthorised users to an error or home page.
149
+ - **Onboarding flows** — guide new users through a setup wizard.
150
+ - **Feature flag redirects** — redirect users when a feature is disabled.
151
+ - **Subdomain-specific redirects** — route admin vs. public subdomains to different paths.
152
+ - **Maintenance mode** — redirect all traffic to a maintenance page when a flag is set.
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ doc
10
10
  .yardoc
11
11
  measurement
12
12
  rubycritic
13
+ .claude/state