tarquinn 0.5.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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -10
- data/.claude/agents/architect.md +45 -0
- data/.claude/agents/ruby.md +39 -0
- data/.claude/scripts/check_ruby.sh +8 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -188
- data/.github/pull_request_template.md +17 -0
- data/.github/tarquinn-usage.md +152 -0
- data/.gitignore +1 -0
- data/AGENTS.md +221 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +2 -2
- data/Gemfile +12 -12
- data/README.md +3 -3
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +20 -0
- data/docs/agents/contributing.md +150 -0
- data/docs/agents/flow.md +5 -0
- data/docs/agents/folder-structure.md +14 -0
- data/docs/agents/issue-enhancement.md +10 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/tarquinn/class_methods.rb +3 -3
- data/lib/tarquinn/version.rb +1 -1
- data/scripts/bump_version.sh +62 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +2 -2
- data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +1 -1
- data/spec/dummy/config/initializers/content_security_policy.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +1 -0
- data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -5
- data/spec/lib/tarquinn/redirection_handler_spec.rb +4 -4
- data/spec/lib/tarquinn_spec.rb +3 -3
- data/tarquinn.gemspec +2 -2
- 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
data/Gemfile
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
|
-
gem 'bundler',
|
|
6
|
-
gem 'pry',
|
|
7
|
-
gem 'pry-nav',
|
|
8
|
-
gem 'rails',
|
|
9
|
-
gem 'rake',
|
|
10
|
-
gem 'rspec',
|
|
11
|
-
gem 'rspec-rails',
|
|
12
|
-
gem 'rubycritic',
|
|
13
|
-
gem 'simplecov',
|
|
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
14
|
gem 'simplecov-lcov', '0.9.0'
|
|
15
|
-
gem 'sqlite3',
|
|
16
|
-
gem 'yard',
|
|
17
|
-
gem 'yardstick',
|
|
15
|
+
gem 'sqlite3', '2.10.2'
|
|
16
|
+
gem 'yard', '0.9.45'
|
|
17
|
+
gem 'yardstick', '0.9.9'
|
|
18
18
|
|
|
19
19
|
gemspec
|
data/README.md
CHANGED
|
@@ -10,13 +10,13 @@ Tarquinn
|
|
|
10
10
|
|
|
11
11
|
Yard Documentation
|
|
12
12
|
-------------------
|
|
13
|
-
[https://www.rubydoc.info/gems/tarquinn/0.
|
|
13
|
+
[https://www.rubydoc.info/gems/tarquinn/1.0.0](https://www.rubydoc.info/gems/tarquinn/1.0.0)
|
|
14
14
|
|
|
15
15
|
This gem makes easier to controll generic redirection
|
|
16
16
|
|
|
17
|
-
Current Release
|
|
17
|
+
**Current Release**: [1.0.0](https://github.com/darthjee/tarquinn/tree/1.0.0)
|
|
18
18
|
|
|
19
|
-
Next
|
|
19
|
+
**Next release**: [1.1.0](https://github.com/darthjee/tarquinn/compare/1.0.0...main)
|
|
20
20
|
|
|
21
21
|
Getting started
|
|
22
22
|
---------------
|
|
@@ -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
|
+
```
|
data/docs/agents/flow.md
ADDED
|
@@ -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
|
|
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
|
|
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
|
|
88
|
+
# @return [Array] current registered conditions
|
|
89
89
|
#
|
|
90
90
|
# @example A redirection with method style condition
|
|
91
91
|
# class ApplicationController < ActionController::Base
|
data/lib/tarquinn/version.rb
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Usage: scripts/bump_version.sh [major|minor|patch|X.Y.Z]
|
|
3
|
+
# Without arguments, bumps the patch version of the current version.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
ROOT="$(git rev-parse --show-toplevel)"
|
|
8
|
+
README="$ROOT/README.md"
|
|
9
|
+
VERSION_FILE="$ROOT/lib/tarquinn/version.rb"
|
|
10
|
+
LOCKFILE="$ROOT/Gemfile.lock"
|
|
11
|
+
GEM="tarquinn"
|
|
12
|
+
|
|
13
|
+
current=$(grep -oE "VERSION = '[0-9]+\.[0-9]+\.[0-9]+'" "$VERSION_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
|
|
14
|
+
IFS='.' read -r cmajor cminor cpatch <<< "$current"
|
|
15
|
+
|
|
16
|
+
arg="${1:-patch}"
|
|
17
|
+
|
|
18
|
+
case "$arg" in
|
|
19
|
+
major) new_version="$((cmajor + 1)).0.0" ;;
|
|
20
|
+
minor) new_version="${cmajor}.$((cminor + 1)).0" ;;
|
|
21
|
+
patch) new_version="${cmajor}.${cminor}.$((cpatch + 1))" ;;
|
|
22
|
+
*) new_version="$arg" ;;
|
|
23
|
+
esac
|
|
24
|
+
|
|
25
|
+
# Validate semver format
|
|
26
|
+
if ! echo "$new_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
|
27
|
+
echo "Error: version must be major, minor, patch or X.Y.Z" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Next release: following minor
|
|
32
|
+
IFS='.' read -r major minor _patch <<< "$new_version"
|
|
33
|
+
next_release="${major}.$((minor + 1)).0"
|
|
34
|
+
|
|
35
|
+
echo "Current version: $current"
|
|
36
|
+
echo "New version: $new_version"
|
|
37
|
+
echo "Next release: $next_release"
|
|
38
|
+
|
|
39
|
+
# version.rb
|
|
40
|
+
sed -i '' "s|VERSION = '[0-9.]*'|VERSION = '${new_version}'|" "$VERSION_FILE"
|
|
41
|
+
|
|
42
|
+
# README: YARD docs link
|
|
43
|
+
sed -i '' \
|
|
44
|
+
"s|rubydoc.info/gems/${GEM}/[0-9.]*|rubydoc.info/gems/${GEM}/${new_version}|g" \
|
|
45
|
+
"$README"
|
|
46
|
+
|
|
47
|
+
# README: Current Release line
|
|
48
|
+
sed -i '' \
|
|
49
|
+
"s|\*\*Current Release\*\*: \[[0-9.]*\](https://github.com/darthjee/tarquinn/tree/[0-9.]*)|**Current Release**: [${new_version}](https://github.com/darthjee/tarquinn/tree/${new_version})|" \
|
|
50
|
+
"$README"
|
|
51
|
+
|
|
52
|
+
# README: Next release line
|
|
53
|
+
sed -i '' \
|
|
54
|
+
"s|\*\*Next release\*\*: \[[0-9.]*\](https://github.com/darthjee/tarquinn/compare/[0-9.]*\.\.\.main)|**Next release**: [${next_release}](https://github.com/darthjee/tarquinn/compare/${new_version}...main)|" \
|
|
55
|
+
"$README"
|
|
56
|
+
|
|
57
|
+
# Gemfile.lock
|
|
58
|
+
if [ -f "$LOCKFILE" ]; then
|
|
59
|
+
sed -i '' "s|^\( *${GEM} (\)[0-9.]*)|\1${new_version})|" "$LOCKFILE"
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
echo "Done."
|