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
data/AGENTS.md ADDED
@@ -0,0 +1,221 @@
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.
189
+
190
+ ## Documentation
191
+
192
+ All project documentation lives under [`docs/agents/`](docs/agents/):
193
+
194
+ | File | Contents |
195
+ |------|----------|
196
+ | [Folder Structure](docs/agents/folder-structure.md) | Top-level directory layout and the role of each folder. |
197
+ | [Architecture](docs/agents/architecture.md) | Source layout, modules, code style, and implementation guidelines. |
198
+ | [Contributing](docs/agents/contributing.md) | Commit guidelines, PR standards, code organization, and refactoring rules. |
199
+ | [Flow](docs/agents/flow.md) | Main runtime flow of the application. |
200
+ | [Plans](docs/agents/plans/) | Implementation plans for ongoing or upcoming features. |
201
+ | [Issues](docs/agents/issues/) | Detailed specs for open issues. |
202
+
203
+ ### Issues (`docs/agents/issues/`)
204
+
205
+ Each file documents an issue in detail. Naming convention:
206
+
207
+ ```
208
+ docs/agents/issues/<issue_id>_<issue_name>.md
209
+ ```
210
+
211
+ Example: `docs/agents/issues/5_release_docker_image.md` for issue #5.
212
+
213
+ ### Plans (`docs/agents/plans/`)
214
+
215
+ Each plan is a directory named after the issue ID and topic, containing one or more related files:
216
+
217
+ ```
218
+ docs/agents/plans/<issue_id>_<topic>/<related_files>.md
219
+ ```
220
+
221
+ Example: `docs/agents/plans/12_add-auth/plan.md` for issue #12.
data/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ See [AGENTS.md](AGENTS.md) for project instructions.
data/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
- FROM darthjee/scripts:0.6.0 as scripts
1
+ FROM darthjee/scripts:0.15.0 as scripts
2
2
 
3
- FROM darthjee/ruby_331:1.0.1 as base
3
+ FROM darthjee/ruby_3412:1.0.0 as base
4
4
 
5
5
  COPY --chown=app:app ./ /home/app/app/
6
6
 
data/Gemfile CHANGED
@@ -2,17 +2,18 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'bundler', '~> 2.5.13'
6
- gem 'pry', '~> 0.14.2'
7
- gem 'pry-nav', '~> 1.0.0'
8
- gem 'rails', '7.2.3'
9
- gem 'rake', '~> 13.1.0'
10
- gem 'rspec', '~> 3.12.0'
11
- gem 'rspec-rails', '6.1.1'
12
- gem 'rubycritic', '4.9.1'
13
- gem 'simplecov', '~> 0.22.0'
14
- gem 'sqlite3', '1.4.2'
15
- gem 'yard', '0.9.38'
16
- gem 'yardstick', '0.9.9'
5
+ gem 'bundler', '>= 4.0.24'
6
+ gem 'pry', '0.14.2'
7
+ gem 'pry-nav', '~> 1.0.0'
8
+ gem 'rails', '7.2.4'
9
+ gem 'rake', '13.4.2'
10
+ gem 'rspec', '3.13.2'
11
+ gem 'rspec-rails', '8.1.0'
12
+ gem 'rubycritic', '5.0.0'
13
+ gem 'simplecov', '0.22.0'
14
+ gem 'simplecov-lcov', '0.9.0'
15
+ gem 'sqlite3', '2.10.2'
16
+ gem 'yard', '0.9.45'
17
+ gem 'yardstick', '0.9.9'
17
18
 
18
19
  gemspec
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  Tarquinn
2
2
  ========
3
3
  [![Build Status](https://circleci.com/gh/darthjee/tarquinn.svg?style=shield)](https://circleci.com/gh/darthjee/tarquinn)
4
- [![Code Climate](https://codeclimate.com/github/darthjee/tarquinn/badges/gpa.svg)](https://codeclimate.com/github/darthjee/tarquinn)
4
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4e950bac9e434e8db64448da42e78793)](https://app.codacy.com/gh/darthjee/tarquinn/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/4e950bac9e434e8db64448da42e78793)](https://app.codacy.com/gh/darthjee/tarquinn/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
5
6
  [![Gem Version](https://badge.fury.io/rb/tarquinn.svg)](https://badge.fury.io/rb/tarquinn)
6
7
  [![Inline docs](http://inch-ci.org/github/darthjee/tarquinn.svg)](http://inch-ci.org/github/darthjee/tarquinn)
7
8
 
@@ -9,13 +10,13 @@ Tarquinn
9
10
 
10
11
  Yard Documentation
11
12
  -------------------
12
- [https://www.rubydoc.info/gems/tarquinn/0.4.0](https://www.rubydoc.info/gems/tarquinn/0.4.0)
13
+ [https://www.rubydoc.info/gems/tarquinn/1.0.0](https://www.rubydoc.info/gems/tarquinn/1.0.0)
13
14
 
14
15
  This gem makes easier to controll generic redirection
15
16
 
16
- Current Release: [0.4.0](https://github.com/darthjee/tarquinn/tree/0.4.0)
17
+ **Current Release**: [1.0.0](https://github.com/darthjee/tarquinn/tree/1.0.0)
17
18
 
18
- Next Version [0.4.1](https://github.com/darthjee/tarquinn/compare/0.4.0...main)
19
+ **Next release**: [1.1.0](https://github.com/darthjee/tarquinn/compare/1.0.0...main)
19
20
 
20
21
  Getting started
21
22
  ---------------
@@ -143,7 +144,9 @@ bundle exec rake verify_measurements
143
144
 
144
145
  You can specify a `domain` option in your `redirection_rule` to allow cross-domain redirection. When set, the redirection will be allowed to external hosts and the specified domain will be used for validation.
145
146
 
146
- **Example:**
147
+ The `domain:` option accepts either a **String** (static domain) or a **Symbol** (dynamic domain resolved at runtime by calling the named method on the controller).
148
+
149
+ **Static domain (String):**
147
150
 
148
151
  ```ruby
149
152
  class ExternalRedirectController < ApplicationController
@@ -161,5 +164,30 @@ class ExternalRedirectController < ApplicationController
161
164
  end
162
165
  ```
163
166
 
167
+ **Dynamic domain (Symbol):**
168
+
169
+ ```ruby
170
+ class ExternalRedirectController < ApplicationController
171
+ include Tarquinn
172
+
173
+ redirection_rule :redirect_external, domain: :current_domain do
174
+ params[:should_redirect]
175
+ end
176
+
177
+ private
178
+
179
+ def redirect_external
180
+ '/external_path'
181
+ end
182
+
183
+ def current_domain
184
+ # resolved at request time
185
+ request.subdomain == 'admin' ? 'admin.example.com' : 'example.com'
186
+ end
187
+ end
188
+ ```
189
+
164
190
  - If `domain` is not set, redirection is only allowed for the same host.
165
- - If `domain` is set, redirection to the specified domain is allowed.
191
+ - If `domain` is a String, it is used directly as the domain prefix.
192
+ - If `domain` is a Symbol and the controller responds to that method, the method is called and its return value is used as the domain.
193
+ - If `domain` is a Symbol but the controller does not respond to it, the Symbol's string representation is used as the domain.
@@ -0,0 +1,9 @@
1
+ # Arcanum Split Issue
2
+
3
+ A checklist of concerns to consider when splitting a broad issue into sub-issues via `/arcanum-split-issue`. Not exhaustive — adjust or extend the list for this project's needs.
4
+
5
+ - **Sub-issue granularity** — is each sub-issue independently workable, or does it still depend on another sub-issue landing first?
6
+ - **Standalone clarity** — does each sub-issue stand on its own, without requiring the reader to have the parent issue open to understand it?
7
+ - **Shared contracts** — interfaces, schemas, or config keys touched by more than one sub-issue, and who owns getting them right first.
8
+ - **Sequencing** — is there a natural order sub-issues should be implemented/merged in, or can they proceed in parallel?
9
+ - **Responsible agents** — which specialist agent(s) each sub-issue is likely to fall to.
@@ -0,0 +1,20 @@
1
+ # Architecture
2
+
3
+ ## Overview
4
+
5
+ Tarquinn is a Ruby gem: an `ActiveSupport::Concern` that adds a `before_action :perform_redirection` and a class-level DSL (`redirection_rule`, `skip_redirection`, `skip_redirection_rule`) to Rails controllers.
6
+
7
+ ## Source Code Layout
8
+
9
+ All source lives under `lib/`; `lib/tarquinn.rb` is the concern.
10
+
11
+ ### `lib/tarquinn/`
12
+
13
+ - `class_methods.rb` – DSL methods added to controllers.
14
+ - `request_handler_builder.rb` / `redirection_config_builder.rb` – accumulate redirection configs per controller class.
15
+ - `request_handler.rb` – processes a request, finding the first matching redirect.
16
+ - `redirection_handler.rb` – evaluates one config (conditions + skip rules).
17
+ - `redirection_config.rb`, `redirection_config/options.rb` – data for one rule.
18
+ - `condition.rb`, `condition/` (`action_checker`, `method_caller`, `proc_runner`) – condition evaluation.
19
+ - `controller.rb` – thin wrapper around the Rails controller.
20
+ - `exception.rb`, `version.rb`.
@@ -0,0 +1,150 @@
1
+ # Contributing
2
+
3
+ ## Commit Guidelines
4
+
5
+ - **Atomic and Unitary:** Each commit must represent a single logical change.
6
+ *Example:*
7
+ - Good: `Add needs_params? method to RedirectionConfig`
8
+ - Bad: `Add needs_params? and refactor RequestHandler logic`
9
+ - **No Unrelated Changes:** Do not mix unrelated changes in the same commit.
10
+ - **Separate Refactoring:** Whenever possible, separate refactoring commits from new feature or bugfix commits.
11
+
12
+ ## Pull Requests
13
+
14
+ - **Descriptive Summary:** Every PR must include a clear and descriptive summary of its purpose and changes.
15
+ - **PR Description Files:** If a description cannot be provided directly in the PR, generate a file with the PR description (e.g., `docs/issues/<pr_number>_description.md`), but do not commit this file.
16
+
17
+ ## Definition of Done for PRs
18
+
19
+ A PR is considered complete when:
20
+
21
+ - The stated objective has been achieved.
22
+ - All tests are passing.
23
+ - Linting passes without errors.
24
+ - Code coverage is as high as reasonably possible.
25
+ - Code is not overly complex:
26
+ - Classes and methods should have clear, focused responsibilities.
27
+ - If a class or method is taking on too many responsibilities, refactor to simplify.
28
+ - Methods should be small and do exactly one thing. If a method is growing, extract parts into private helper methods or separate classes.
29
+ - *Example:*
30
+
31
+ ```ruby
32
+ # Good: Each method does one thing
33
+ class Worker
34
+ def fetch_job; end
35
+ def process_job(job); end
36
+ end
37
+
38
+ # Bad: Method does too much
39
+ class Worker
40
+ def run
41
+ fetch_job
42
+ process_job
43
+ send_metrics
44
+ cleanup
45
+ end
46
+ end
47
+ ```
48
+
49
+ - This requirement applies primarily to source code. For specs, refactor only if there is excessive duplication.
50
+
51
+ ### CI Checks
52
+
53
+ Before a PR is considered complete, all CI checks relevant to the modified parts of the project must pass locally. The project is a single gem, so both CircleCI jobs apply to any change under `lib/`, `spec/` or `config/`:
54
+
55
+ | Job | Local commands |
56
+ | --- | --- |
57
+ | `test` | `bundle exec rspec` |
58
+ | `checks` | `rubocop`, `bundle exec rake verify_measurements` (Yardstick), `check_readme.sh`, `rubycritic.sh`, `check_specs` |
59
+
60
+ Development and test containers are available via `make dev` and `make tests`.
61
+
62
+ This same process must be followed when **planning how to resolve an issue**: include a final step in the plan that lists the CI commands to run before opening a PR.
63
+
64
+ ## Code Organization
65
+
66
+ ### File Responsibility: Class Declarers vs Scripts
67
+
68
+ Every source file (excluding specs) must act as a **class declarer** — it should define one or more classes or modules, and must not execute logic or cause side effects at load time.
69
+
70
+ The only exception is `lib/tarquinn.rb`, which is the entry point (the `ActiveSupport::Concern` included by controllers) and requires the other files.
71
+
72
+ *Example:*
73
+
74
+ ```ruby
75
+ # Good: class declarer
76
+ class Tarquinn::RequestHandler
77
+ def process; end
78
+ end
79
+
80
+ # Bad: script — executes logic at load time
81
+ handler = Tarquinn::RequestHandler.new
82
+ handler.process
83
+ ```
84
+
85
+ Spec files are exempt from this rule.
86
+
87
+ ### File Naming: snake_case for Class Files
88
+
89
+ Files that define a class must use **snake_case** naming matching the class name, and spec files append `_spec`.
90
+
91
+ *Examples:*
92
+
93
+ - `request_handler.rb` for `Tarquinn::RequestHandler`
94
+ - `redirection_config.rb` for `Tarquinn::RedirectionConfig`
95
+
96
+ Specs mirror the source path: `lib/tarquinn/request_handler.rb` → `spec/lib/tarquinn/request_handler_spec.rb`.
97
+
98
+ ### Method Order: Public Before Private
99
+
100
+ Within a class, **public methods must be declared before private methods**. Private helpers go at the end of the class body, after `private`.
101
+
102
+ ```ruby
103
+ # Good
104
+ class Worker
105
+ def run
106
+ prepare
107
+ execute
108
+ end
109
+
110
+ private
111
+
112
+ def prepare; end
113
+ def execute; end
114
+ end
115
+ ```
116
+
117
+ ## Dependency Injection
118
+
119
+ Classes must receive their dependencies (data, configuration, collaborators) as constructor arguments. A class must never reach out to load files, read environment variables, or fetch configuration on its own.
120
+
121
+ *Example:*
122
+
123
+ ```ruby
124
+ # Good: receives data — easy to test
125
+ class Router
126
+ def initialize(data)
127
+ @data = data
128
+ end
129
+ end
130
+
131
+ # Bad: loads its own config
132
+ class Router
133
+ def build
134
+ data = YAML.load_file('./data.yml')
135
+ end
136
+ end
137
+ ```
138
+
139
+ ## Refactoring Guidelines
140
+
141
+ When refactoring, aim to:
142
+
143
+ - **Reduce Code Duplication:** Move repeated spec setup into `let` definitions or shared examples (`spec/support/shared_examples`).
144
+
145
+ ```ruby
146
+ # Good
147
+ let(:category) { build_category(id: 2) }
148
+
149
+ # Bad: the same hash repeated in many examples
150
+ ```
@@ -0,0 +1,5 @@
1
+ # Flow
2
+
3
+ ## Overview
4
+
5
+ _Describe the main runtime flow of the application here._
@@ -0,0 +1,14 @@
1
+ # Folder Structure
2
+
3
+ ## Project Root
4
+
5
+ | Directory / File | Description |
6
+ |---|---|
7
+ | `lib/` | Gem source code (`tarquinn.rb` entry point and `tarquinn/` internals). |
8
+ | `spec/` | RSpec suite: unit specs in `lib/`, shared examples in `support/`, and a Rails `dummy/` app for integration. |
9
+ | `config/` | Quality-tool configs (check_specs, rubycritic, yardstick). |
10
+ | `docs/agents/` | Agent-facing docs: architecture, flow, issues, plans. |
11
+ | `.github/` | PR/commit templates, Copilot usage notes. |
12
+ | `.circleci/` | CI pipeline. |
13
+ | `tarquinn.gemspec`, `Gemfile`, `Rakefile` | Gem packaging and tasks. |
14
+ | `Dockerfile`, `docker-compose.yml`, `Makefile` | Dev/test container tooling. |
@@ -0,0 +1,10 @@
1
+ # Issue Enhancement
2
+
3
+ A checklist of concerns to consider when fleshing out a vague issue idea (tagged `Idea`/`Writting`) before it reaches the `Created` stage. Not exhaustive — adjust or extend the list for this project's needs.
4
+
5
+ - **Scope boundaries** — what's explicitly in scope and what's explicitly out.
6
+ - **Alternative solutions** — other ways to solve the same problem, and why this one was chosen.
7
+ - **Edge cases** — inputs, states, or timing the happy path doesn't cover.
8
+ - **Backward compatibility** — whether this breaks existing behavior, data, or integrations.
9
+ - **Testing strategy** — how the change will be verified.
10
+ - **Performance & security considerations** — anything relevant to load, latency, or attack surface.
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -11,7 +11,7 @@ module Tarquinn
11
11
  #
12
12
  # @param (see Tarquinn::RequestHandlerBuilder#add_redirection_config)
13
13
  # @option (see Tarquinn::RequestHandlerBuilder#add_redirection_config)
14
- # @return (see Tarquinn::RequestHandlerBuilder#add_redirection_config)
14
+ # @return [Tarquinn::RedirectionConfig] the newly built configuration
15
15
  #
16
16
  # @see Tarquinn::RequestHandlerBuilder
17
17
  # @see Tarquinn::RedirectionConfig::Options
@@ -68,7 +68,7 @@ module Tarquinn
68
68
  # When any of the skip rules is met the redirection is skipped
69
69
  #
70
70
  # @param (see Tarquinn::RequestHandlerBuilder#add_skip_action)
71
- # @return (see Tarquinn::RequestHandlerBuilder#add_skip_action)
71
+ # @return [Array<Tarquinn::Condition>] current registered skip conditions
72
72
  #
73
73
  # @example Skip a redirection for a specific group of controller actions
74
74
  # class ApplicationController < ActionController::Base
@@ -85,7 +85,7 @@ module Tarquinn
85
85
  # Methods and blocks are ran and if any returns true, the redirect is skipped
86
86
  #
87
87
  # @param (see Tarquinn::RequestHandlerBuilder#add_skip_config)
88
- # @return (see Tarquinn::RequestHandlerBuilder#add_skip_config)
88
+ # @return [Array] current registered conditions
89
89
  #
90
90
  # @example A redirection with method style condition
91
91
  # class ApplicationController < ActionController::Base
@@ -52,6 +52,23 @@ module Tarquinn
52
52
  controller.respond_to?(method, true)
53
53
  end
54
54
 
55
+ # Resolves a value that may reference a controller method
56
+ #
57
+ # If the value is a Symbol and the controller responds to it, calls the
58
+ # method and returns its result. Otherwise, returns the original value.
59
+ #
60
+ # @overload resolve_callable(method_name)
61
+ # @param method_name [Symbol] method name
62
+ # @overload resolve_callable(value)
63
+ # @param value [String] value to be returned
64
+ #
65
+ # @return [Object] resolved method return or original value
66
+ def resolve_callable(value)
67
+ return value unless value.is_a?(Symbol) && method?(value)
68
+
69
+ call(value)
70
+ end
71
+
55
72
  private
56
73
 
57
74
  # @api private
@@ -19,40 +19,19 @@ module Tarquinn
19
19
  # and not allowed for external hosts.
20
20
  #
21
21
  # if set, the redirection will be allowed for external
22
- # hosts and the domain will be used for validation
22
+ # hosts and the domain will be used for validation.
23
+ # A Symbol value is resolved at runtime via the controller method.
23
24
  #
24
- # @return [String, nil] the domain for cross-domain redirection
25
+ # @return [String, Symbol, nil] the domain for cross-domain redirection
25
26
  # @see RedirectionHandler#redirect
26
- # @see #redirection_options
27
27
 
28
28
  # @method initialize(domain: nil)
29
29
  # @api private
30
30
  # Initializes a new Options object
31
- # @param domain [String, nil] the domain for cross-domain redirection
31
+ # @param domain [String, Symbol, nil] the domain for cross-domain redirection.
32
+ # A String is used as-is; a Symbol is resolved by calling the matching
33
+ # method on the controller at runtime (via {Tarquinn::RedirectionHandler}).
32
34
  # @return [Tarquinn::RedirectionConfig::Options]
33
-
34
- # Options to be passed for the controller on redirect_to
35
- # @return [Hash] the options for the redirection
36
- def redirection_options
37
- {
38
- allow_other_host:
39
- }.compact
40
- end
41
-
42
- # Checks if the domain option is set
43
- # @return [TrueClass] when the domain option is set
44
- # @return [FalseClass] when the domain option is not set
45
- def domain?
46
- domain.present?
47
- end
48
-
49
- private
50
-
51
- # Returns the value of the allow_other_host option
52
- # @return [TrueClass, nil] the value of the allow_other_host option
53
- def allow_other_host
54
- domain? || nil
55
- end
56
35
  end
57
36
  end
58
37
  end