sinclair 3.1.0 → 3.2.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 +4 -5
- data/.claude/agents/architect.md +53 -0
- data/.claude/agents/docs.md +34 -0
- data/.claude/agents/ruby.md +44 -0
- data/.claude/agents/security.md +27 -0
- data/.claude/configuration/arcanum-repo-config.json +8 -0
- data/.claude/configuration/auto-fix-all.json +3 -0
- data/.claude/scripts/check_ruby.sh +7 -0
- data/.claude/settings.json +10 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +8 -0
- data/.github/copilot-instructions.md +1 -66
- data/.github/pull_request_template.md +17 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/AGENTS.md +111 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +3 -2
- data/Dockerfile.circleci +6 -11
- data/Gemfile +10 -9
- data/README.md +2 -2
- data/config/yardstick.yml +6 -0
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +96 -0
- data/docs/agents/contributing.md +201 -0
- data/docs/agents/flow.md +5 -0
- data/docs/agents/folder-structure.md +44 -0
- data/docs/agents/issue-enhancement.md +10 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/docs/guides/sinclair/caster.md +33 -0
- data/docs/guides/sinclair/comparable.md +26 -0
- data/docs/guides/sinclair/complete-example.md +43 -0
- data/docs/guides/sinclair/configurable.md +55 -0
- data/docs/guides/sinclair/env-settable.md +41 -0
- data/docs/guides/sinclair/installation.md +17 -0
- data/docs/guides/sinclair/matchers.md +52 -0
- data/docs/guides/sinclair/method-builder.md +104 -0
- data/docs/guides/sinclair/model.md +75 -0
- data/docs/guides/sinclair/options.md +33 -0
- data/docs/guides/sinclair-usage.md +39 -0
- data/lib/sinclair/caster.rb +1 -1
- data/lib/sinclair/core_ext/object.rb +2 -2
- data/lib/sinclair/version.rb +1 -1
- data/scripts/bump_version.sh +62 -0
- data/sinclair.gemspec +1 -1
- data/spec/integration/yard/sinclair/caster/cast_spec.rb +1 -1
- data/spec/lib/sinclair/config_factory_spec.rb +5 -10
- data/spec/lib/sinclair/configurable_spec.rb +3 -6
- data/spec/lib/sinclair/method_definition/stringifier_spec.rb +1 -1
- data/spec/lib/sinclair/options_parser_spec.rb +1 -1
- data/spec/support/models/hash_app_client.rb +1 -2
- metadata +37 -8
- data/.github/sinclair-usage.md +0 -492
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Sinclair is a small, dependency-light Ruby gem (built on top of `active_support`) whose
|
|
6
|
+
core class, `Sinclair`, is a **method builder**: it collects method definitions
|
|
7
|
+
(from strings, blocks, or delegated calls) and, on `#build`, evaluates them onto a
|
|
8
|
+
target class as instance or class methods. Everything else in the gem is either a
|
|
9
|
+
supporting concern used by `Sinclair` itself, or a standalone module that other gems
|
|
10
|
+
can mix in independently (configuration, options parsing, env-var reading, model
|
|
11
|
+
generation, comparison, RSpec matchers).
|
|
12
|
+
|
|
13
|
+
All top-level constants are `autoload`ed from `lib/sinclair.rb`, so requiring `sinclair`
|
|
14
|
+
does not eagerly load the whole tree — each file under `lib/sinclair/` is only loaded
|
|
15
|
+
when its constant is first referenced.
|
|
16
|
+
|
|
17
|
+
## Source Code Layout
|
|
18
|
+
|
|
19
|
+
All application source code lives under `lib/sinclair/`, plus the entry point `lib/sinclair.rb`.
|
|
20
|
+
|
|
21
|
+
### `lib/sinclair.rb`
|
|
22
|
+
|
|
23
|
+
Defines the `Sinclair` class itself: `#initialize`, `#add_method`, `#add_class_method`,
|
|
24
|
+
`#eval_and_add_method`, and `#build`. Declares every `autoload` for the gem's public
|
|
25
|
+
constants and includes `OptionsParser` / extends `ClassMethods` (the `Sinclair.build`
|
|
26
|
+
class-level entry point).
|
|
27
|
+
|
|
28
|
+
### `method_definition/` and `method_definition.rb`
|
|
29
|
+
|
|
30
|
+
Represents a single method to be built. `MethodDefinition` dispatches to one of:
|
|
31
|
+
- `StringDefinition` — method body given as a code string.
|
|
32
|
+
- `BlockDefinition` — method body given as a block.
|
|
33
|
+
- `CallDefinition` — delegates to another method call (e.g. `attr_accessor`).
|
|
34
|
+
|
|
35
|
+
`ParameterBuilder`/`ParameterHelper` and `BlockHelper` support argument handling and
|
|
36
|
+
block evaluation; `Stringifier` turns definitions into evaluable code strings.
|
|
37
|
+
`MethodDefinitions` (plural, top-level file) is the collection object that `Sinclair`
|
|
38
|
+
uses to accumulate instance/class method definitions before building.
|
|
39
|
+
|
|
40
|
+
### `method_builder/` and `method_builder.rb`
|
|
41
|
+
|
|
42
|
+
Takes a `MethodDefinitions` collection and actually defines the methods on the target
|
|
43
|
+
class via `define_method`/`class_eval`. `Base` holds shared logic; `BlockMethodBuilder`,
|
|
44
|
+
`CallMethodBuilder`, and `StringMethodBuilder` handle each definition type.
|
|
45
|
+
|
|
46
|
+
### `options/`, `options.rb`, `options_parser.rb`
|
|
47
|
+
|
|
48
|
+
`Sinclair::Options` — a DSL (`Builder`, `ClassMethods`) for declaring structured,
|
|
49
|
+
validated option objects (used internally for `Sinclair`'s own `options` hash, and
|
|
50
|
+
usable standalone). `OptionsParser` is the concern `Sinclair` includes to expose
|
|
51
|
+
`options_object` inside builders/blocks.
|
|
52
|
+
|
|
53
|
+
### `config/`, `config.rb`, `config_builder.rb`, `config_class.rb`, `config_factory.rb`, `configurable.rb`
|
|
54
|
+
|
|
55
|
+
`Sinclair::Configurable` / `Sinclair::Config` — adds a `configure`/`config` pattern to
|
|
56
|
+
any class or module. `ConfigFactory` and `ConfigBuilder` build the backing `ConfigClass`;
|
|
57
|
+
`config/methods_builder.rb` wires the generated accessor methods.
|
|
58
|
+
|
|
59
|
+
### `settable/`, `settable.rb`, `env_settable.rb`, `chain_settable.rb`
|
|
60
|
+
|
|
61
|
+
`Sinclair::EnvSettable` — declares class methods that read from `ENV`, with type
|
|
62
|
+
casting. `Settable` is the shared engine (`Builder`, `Caster`, `ClassMethods`);
|
|
63
|
+
`ChainSettable` supports chaining multiple settable sources; `EnvSettable` is the
|
|
64
|
+
env-var-specific façade.
|
|
65
|
+
|
|
66
|
+
### `caster/`, `caster.rb`
|
|
67
|
+
|
|
68
|
+
Shared type-casting logic (`ClassMethods`) reused by both `Options` and `Settable` to
|
|
69
|
+
coerce raw input values (strings, env vars) into typed Ruby values.
|
|
70
|
+
|
|
71
|
+
### `model/`, `model.rb`
|
|
72
|
+
|
|
73
|
+
`Sinclair::Model` — helpers for quickly defining plain-Ruby model classes, either via
|
|
74
|
+
`initialize_with` in the class body (`BuilderOptions`, `Builder`) or via `.for` as an
|
|
75
|
+
inline subclassing helper.
|
|
76
|
+
|
|
77
|
+
### `comparable/`, `comparable.rb`, `equals_checker/`, `equals_checker.rb`
|
|
78
|
+
|
|
79
|
+
`Sinclair::Comparable` — mixin that implements `==` based on a declared list of
|
|
80
|
+
attributes. `EqualsChecker` (with `Reader`) does the actual attribute comparison.
|
|
81
|
+
|
|
82
|
+
### `matchers/`, `matchers.rb`
|
|
83
|
+
|
|
84
|
+
`Sinclair::Matchers` — RSpec matchers (`add_method`, `add_class_method`,
|
|
85
|
+
`add_instance_method`, `change_method`, `change_class_method`, `change_instance_method`,
|
|
86
|
+
and their `_to`/`_on` fluent variants) for asserting on `Sinclair`-based builders'
|
|
87
|
+
behavior in specs. `Base` holds shared matcher logic.
|
|
88
|
+
|
|
89
|
+
### `core_ext/`
|
|
90
|
+
|
|
91
|
+
Small core Ruby extensions (`Object`) used internally by the gem.
|
|
92
|
+
|
|
93
|
+
### `input_hash.rb`, `exception.rb`, `class_methods.rb`, `version.rb`
|
|
94
|
+
|
|
95
|
+
Supporting top-level files: `InputHash` (hash-input normalization), `Exception` (gem
|
|
96
|
+
error hierarchy), `ClassMethods` (`Sinclair.build`), `VERSION` (gem version constant).
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Commit Guidelines
|
|
4
|
+
|
|
5
|
+
- **Atomic and Unitary:** Each commit must represent a single logical change.
|
|
6
|
+
*Example:*
|
|
7
|
+
- Good: `Add cached option to MethodDefinition`
|
|
8
|
+
- Bad: `Add cached option and refactor MethodBuilder`
|
|
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/agents/issues/<issue_id>_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 (pseudo-code):*
|
|
30
|
+
```ruby
|
|
31
|
+
# Good: Each method does one thing
|
|
32
|
+
class Worker
|
|
33
|
+
def fetch_job
|
|
34
|
+
# ...
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def process_job(job)
|
|
38
|
+
# ...
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Bad: Method does too much
|
|
43
|
+
class Worker
|
|
44
|
+
def run
|
|
45
|
+
fetch_job
|
|
46
|
+
process_job(job)
|
|
47
|
+
send_metrics
|
|
48
|
+
cleanup
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
- This requirement applies primarily to source code. For specs, refactor only if there is excessive duplication.
|
|
53
|
+
|
|
54
|
+
### CI Checks
|
|
55
|
+
|
|
56
|
+
Before a PR is considered complete, all CI checks defined in `.circleci/config.yml` must pass locally. This is a single-gem project (not a monorepo), so every job below applies to every change — there is no folder-based filtering.
|
|
57
|
+
|
|
58
|
+
| Job | Local command(s) |
|
|
59
|
+
|-----|-------------------|
|
|
60
|
+
| `test` | `bundle exec rspec` |
|
|
61
|
+
| `checks` | `rubocop`, `bundle exec rake verify_measurements` (Yardstick doc coverage), `check_specs` (spec-per-source-file coverage) |
|
|
62
|
+
| `build-and-release` | Release-only (gem build/push on tagged `master` builds) — not required for PRs |
|
|
63
|
+
|
|
64
|
+
All commands above must be run **inside the docker-compose container**, not with the host's Ruby — either from a `make dev` shell or prefixed with `docker-compose run --rm sinclair` (e.g. `docker-compose run --rm sinclair bundle exec rspec`). Rebuild the image with `docker-compose build base_build` after changing the `Gemfile` or `Dockerfile`.
|
|
65
|
+
|
|
66
|
+
Run all `test` and `checks` commands above before opening a PR. If new CircleCI jobs are added in the future, update this table.
|
|
67
|
+
|
|
68
|
+
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 above to run before opening a PR.
|
|
69
|
+
|
|
70
|
+
## Code Organization
|
|
71
|
+
|
|
72
|
+
### File Responsibility: Class Declarers vs Scripts
|
|
73
|
+
|
|
74
|
+
Every source file under `lib/` (excluding spec files) must act as a **class or module declarer** — it should define and (via `autoload`, in this gem) expose one class or module. Files must not act as **scripts** (i.e., they must not execute logic at load time or perform side effects directly).
|
|
75
|
+
|
|
76
|
+
*Example:*
|
|
77
|
+
```ruby
|
|
78
|
+
# Good: class declarer — defines a class, no side effects at load time
|
|
79
|
+
class MethodBuilder
|
|
80
|
+
def build(definitions)
|
|
81
|
+
# ...
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Bad: script — executes logic at file-load time
|
|
86
|
+
builder = MethodBuilder.new
|
|
87
|
+
builder.build(definitions)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Spec files are exempt from this rule and may execute setup code (e.g. `describe`/`let`/`before`) freely.
|
|
91
|
+
|
|
92
|
+
### File Naming: snake_case for Class Files
|
|
93
|
+
|
|
94
|
+
Files that define a class or module must use **snake_case** naming, matching the class/module name exactly, with one file per directory level of namespacing.
|
|
95
|
+
|
|
96
|
+
*Examples:*
|
|
97
|
+
|
|
98
|
+
- `method_builder.rb` for `class MethodBuilder`
|
|
99
|
+
- `method_builder/base.rb` for `class MethodBuilder::Base`
|
|
100
|
+
- `equals_checker/reader.rb` for `class EqualsChecker::Reader`
|
|
101
|
+
|
|
102
|
+
This applies to both source files and their corresponding spec files, mirrored under `spec/`:
|
|
103
|
+
- `lib/sinclair/method_builder.rb` → spec: `spec/lib/sinclair/method_builder_spec.rb`
|
|
104
|
+
- `lib/sinclair/equals_checker/reader.rb` → spec: `spec/lib/sinclair/equals_checker/reader_spec.rb`
|
|
105
|
+
|
|
106
|
+
Non-class files (e.g. plain utility scripts outside `lib/`) use snake_case at the author's discretion.
|
|
107
|
+
|
|
108
|
+
### Method Order: Public Before Private
|
|
109
|
+
|
|
110
|
+
Within a class, **public methods must be declared before private methods**. Private methods (below the `private` keyword) serve as implementation helpers and should appear at the end of the class body.
|
|
111
|
+
|
|
112
|
+
*Example:*
|
|
113
|
+
```ruby
|
|
114
|
+
# Good: public methods first, private methods last
|
|
115
|
+
class Worker
|
|
116
|
+
def run
|
|
117
|
+
prepare
|
|
118
|
+
execute
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def status
|
|
122
|
+
# ...
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def prepare
|
|
128
|
+
# ...
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def execute
|
|
132
|
+
# ...
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Bad: private methods mixed in with or before public methods
|
|
137
|
+
class Worker
|
|
138
|
+
private
|
|
139
|
+
|
|
140
|
+
def prepare
|
|
141
|
+
# ...
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
public
|
|
145
|
+
|
|
146
|
+
def run
|
|
147
|
+
# ...
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Dependency Injection
|
|
153
|
+
|
|
154
|
+
Classes must receive their dependencies (data, configuration, collaborators) as constructor arguments (`initialize`). A class must never reach out to load files, read environment variables, or fetch configuration on its own — the exception is `Sinclair::EnvSettable`/`Sinclair::Config`, whose entire purpose is to be that boundary; classes that use them should still receive the resulting values, not read `ENV` or config directly themselves.
|
|
155
|
+
|
|
156
|
+
This makes every class independently testable: specs simply instantiate the class with the data they need, without touching the filesystem or environment.
|
|
157
|
+
|
|
158
|
+
*Example:*
|
|
159
|
+
```ruby
|
|
160
|
+
# Good: class receives data as an argument — easy to test
|
|
161
|
+
class Router
|
|
162
|
+
def initialize(data)
|
|
163
|
+
@data = data
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def build
|
|
167
|
+
# ...
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Bad: class loads its own config — hard to test and couples to the filesystem
|
|
172
|
+
class Router
|
|
173
|
+
def build
|
|
174
|
+
data = YAML.load_file('./data.yml') # ❌
|
|
175
|
+
# ...
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This principle applies to all classes — including helpers and builders. If a class needs data, it gets it through its constructor.
|
|
181
|
+
|
|
182
|
+
## Refactoring Guidelines
|
|
183
|
+
|
|
184
|
+
When refactoring, aim to:
|
|
185
|
+
|
|
186
|
+
- **Reduce Code Duplication:**
|
|
187
|
+
*Example:* Move repeated setup code in specs to a factory method.
|
|
188
|
+
```ruby
|
|
189
|
+
# Good
|
|
190
|
+
def build_category(**attrs)
|
|
191
|
+
{ id: 1, name: 'Books', **attrs }
|
|
192
|
+
end
|
|
193
|
+
# In specs:
|
|
194
|
+
category = build_category(id: 2)
|
|
195
|
+
|
|
196
|
+
# Bad
|
|
197
|
+
category = { id: 2, name: 'Books' }
|
|
198
|
+
# ...repeated in many spec files
|
|
199
|
+
```
|
|
200
|
+
- **Avoid Mocks:** Prefer real objects and stubs only when there is no reasonable alternative (per `AGENTS.md`'s testing guidelines).
|
|
201
|
+
- **Keep One Expectation Per Example:** Split multi-assertion `it` blocks into focused examples.
|
data/docs/agents/flow.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Folder Structure
|
|
2
|
+
|
|
3
|
+
## Project Root
|
|
4
|
+
|
|
5
|
+
| Directory / File | Description |
|
|
6
|
+
|-----------------|-------------|
|
|
7
|
+
| `lib/` | Gem source code (`Sinclair` and its submodules). |
|
|
8
|
+
| `spec/` | RSpec test suite, mirroring the structure of `lib/`. |
|
|
9
|
+
| `config/` | Configuration for dev/CI tooling: `check_specs.yml` (spec coverage exceptions), `rubycritc.rb`, `yardstick.rb`/`yardstick.yml` (YARD documentation coverage). |
|
|
10
|
+
| `docs/agents/` | Agent-facing documentation: architecture, flow, folder structure, contributing, issue checklists, plans, and issues. |
|
|
11
|
+
| `docs/guides/` | User-facing usage guides for the gem's features (`sinclair-usage.md` and per-feature pages under `sinclair/`). |
|
|
12
|
+
| `doc/` | Generated YARD API documentation (build artifact, not hand-maintained). |
|
|
13
|
+
| `.circleci/` | CircleCI pipeline configuration (`config.yml`). |
|
|
14
|
+
| `.github/` | GitHub-specific files: PR/commit message templates and the Copilot pointer to `AGENTS.md`. |
|
|
15
|
+
| `.claude/` | Claude Code configuration: specialist agents (`agents/`), per-agent check scripts (`scripts/`), shared settings, and arcanum repo config (`configuration/`). `state/` is local-only and gitignored. |
|
|
16
|
+
| `AGENTS.md` / `CLAUDE.md` | Shared agent instructions (`CLAUDE.md` just points to `AGENTS.md`). |
|
|
17
|
+
| `Dockerfile` | Image used for local development (`make dev`). |
|
|
18
|
+
| `Dockerfile.circleci` | Image used by the CircleCI pipeline. |
|
|
19
|
+
| `docker-compose.yml` | Defines the `sinclair` development service. |
|
|
20
|
+
| `Makefile` | Shortcuts for common tasks (e.g. `make dev`). |
|
|
21
|
+
| `Rakefile` | Rake tasks, including `verify_measurements` (Yardstick check). |
|
|
22
|
+
| `sinclair.gemspec` | Gem specification (dependencies, metadata). |
|
|
23
|
+
| `Gemfile` | Bundler dependencies. |
|
|
24
|
+
| `.rubocop.yml` / `.rubocop_todo.yml` | Rubocop style configuration. |
|
|
25
|
+
| `.rspec` | RSpec runner configuration. |
|
|
26
|
+
| `README.md` | Project overview and usage documentation. |
|
|
27
|
+
| `WARNINGS.md` | Known warnings/caveats for users of the gem. |
|
|
28
|
+
| `LICENSE` | Project license. |
|
|
29
|
+
|
|
30
|
+
## lib/sinclair (source layout)
|
|
31
|
+
|
|
32
|
+
| Subdirectory | Description |
|
|
33
|
+
|--------------|-------------|
|
|
34
|
+
| `options/` | `Sinclair::Options` — structured, validated option objects. |
|
|
35
|
+
| `core_ext/` | Core Ruby extensions used internally. |
|
|
36
|
+
| `config/` | `Sinclair::Configurable` / `Sinclair::Config` — configuration support for classes and modules. |
|
|
37
|
+
| `caster/` | Type-casting helpers used by options/config. |
|
|
38
|
+
| `settable/` | `Sinclair::EnvSettable` — reading environment variables through class methods. |
|
|
39
|
+
| `model/` | `Sinclair::Model` — quick creation of simple plain-Ruby model classes. |
|
|
40
|
+
| `comparable/`| `Sinclair::Comparable` — `==` comparisons based on selected attributes. |
|
|
41
|
+
| `matchers/` | `Sinclair::Matchers` — RSpec matchers for testing method-building behaviour. |
|
|
42
|
+
| `method_builder/` | Internals for dynamically building instance/class methods. |
|
|
43
|
+
| `method_definition/` | Definition objects describing methods to be built. |
|
|
44
|
+
| `equals_checker/` | Internals backing `Sinclair::Comparable`. |
|
|
@@ -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
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Sinclair::Caster – Type Casting
|
|
2
|
+
|
|
3
|
+
`Sinclair::Caster` provides a registry of named type casters.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
class MyCaster < Sinclair::Caster
|
|
7
|
+
cast_with(:upcase, :upcase)
|
|
8
|
+
cast_with(:log) { |value, base: 10| Math.log(value.to_f, base) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
MyCaster.cast('hello', :upcase) # => 'HELLO'
|
|
12
|
+
MyCaster.cast(100, :log) # => 2.0
|
|
13
|
+
MyCaster.cast(16, :log, base: 2) # => 4.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Class-based casting
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
class TypeCaster < Sinclair::Caster
|
|
20
|
+
master_caster!
|
|
21
|
+
|
|
22
|
+
cast_with(Integer, :to_i)
|
|
23
|
+
cast_with(Float, :to_f)
|
|
24
|
+
cast_with(String, :to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
TypeCaster.cast('42', Integer) # => 42
|
|
28
|
+
TypeCaster.cast(3, Float) # => 3.0
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
[Back to index](../sinclair-usage.md)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Sinclair::Comparable – Attribute-based Equality
|
|
2
|
+
|
|
3
|
+
Include `Sinclair::Comparable` and declare which attributes are used for `==`.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
class Person
|
|
7
|
+
include Sinclair::Comparable
|
|
8
|
+
|
|
9
|
+
comparable_by :name
|
|
10
|
+
attr_reader :name, :age
|
|
11
|
+
|
|
12
|
+
def initialize(name:, age:)
|
|
13
|
+
@name = name
|
|
14
|
+
@age = age
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
p1 = Person.new(name: 'Alice', age: 30)
|
|
19
|
+
p2 = Person.new(name: 'Alice', age: 25)
|
|
20
|
+
|
|
21
|
+
p1 == p2 # => true (only :name is compared)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
[Back to index](../sinclair-usage.md)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Complete Example
|
|
2
|
+
|
|
3
|
+
```ruby
|
|
4
|
+
# Combining multiple Sinclair features in one class
|
|
5
|
+
|
|
6
|
+
class ApiClient
|
|
7
|
+
extend Sinclair::Configurable
|
|
8
|
+
extend Sinclair::EnvSettable
|
|
9
|
+
include Sinclair::Comparable
|
|
10
|
+
|
|
11
|
+
# --- Configuration (set programmatically) ---
|
|
12
|
+
configurable_with :timeout, retries: 3
|
|
13
|
+
|
|
14
|
+
# --- Environment variables ---
|
|
15
|
+
settings_prefix 'API'
|
|
16
|
+
with_settings :api_key, :secret, base_url: 'https://api.example.com'
|
|
17
|
+
|
|
18
|
+
# --- Equality based on base_url ---
|
|
19
|
+
comparable_by :base_url
|
|
20
|
+
|
|
21
|
+
attr_reader :base_url
|
|
22
|
+
|
|
23
|
+
def initialize(base_url: self.class.base_url)
|
|
24
|
+
@base_url = base_url
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Wire up at boot time
|
|
29
|
+
ENV['API_API_KEY'] = 'secret-key'
|
|
30
|
+
ApiClient.configure(timeout: 60)
|
|
31
|
+
|
|
32
|
+
client1 = ApiClient.new
|
|
33
|
+
client2 = ApiClient.new
|
|
34
|
+
|
|
35
|
+
client1 == client2 # => true
|
|
36
|
+
ApiClient.config.timeout # => 60
|
|
37
|
+
ApiClient.config.retries # => 3
|
|
38
|
+
ApiClient.api_key # => 'secret-key'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
[Back to index](../sinclair-usage.md)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Sinclair::Configurable – Application Configuration
|
|
2
|
+
|
|
3
|
+
`Sinclair::Configurable` adds a read-only `config` object to any class or
|
|
4
|
+
module. Settings can only be changed through `configure`.
|
|
5
|
+
|
|
6
|
+
### Inline attributes
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
module MyApp
|
|
10
|
+
extend Sinclair::Configurable
|
|
11
|
+
|
|
12
|
+
configurable_with :host, port: 80, debug: false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
MyApp.configure(port: 5555) do |config|
|
|
16
|
+
config.host 'example.com'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
MyApp.config.host # => 'example.com'
|
|
20
|
+
MyApp.config.port # => 5555
|
|
21
|
+
|
|
22
|
+
MyApp.reset_config
|
|
23
|
+
MyApp.config.host # => nil
|
|
24
|
+
MyApp.config.port # => 80
|
|
25
|
+
|
|
26
|
+
# Convert to Options object (useful for passing around)
|
|
27
|
+
MyApp.as_options(host: 'other').host # => 'other'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Custom config class
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
class ServerConfig < Sinclair::Config
|
|
34
|
+
config_attributes :host, :port
|
|
35
|
+
|
|
36
|
+
def url
|
|
37
|
+
@port ? "http://#{@host}:#{@port}" : "http://#{@host}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Client
|
|
42
|
+
extend Sinclair::Configurable
|
|
43
|
+
configurable_by ServerConfig
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
Client.configure { host 'api.example.com' }
|
|
47
|
+
Client.config.url # => 'http://api.example.com'
|
|
48
|
+
|
|
49
|
+
Client.configure { port 8080 }
|
|
50
|
+
Client.config.url # => 'http://api.example.com:8080'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
[Back to index](../sinclair-usage.md)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Sinclair::EnvSettable – Environment Variable Access
|
|
2
|
+
|
|
3
|
+
`EnvSettable` exposes environment variables as class-level methods, with
|
|
4
|
+
optional prefix and default values.
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
class ServiceClient
|
|
8
|
+
extend Sinclair::EnvSettable
|
|
9
|
+
|
|
10
|
+
settings_prefix 'SERVICE'
|
|
11
|
+
with_settings :username, :password, port: 80, hostname: 'my-host.com'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
ENV['SERVICE_USERNAME'] = 'my-login'
|
|
15
|
+
ENV['SERVICE_HOSTNAME'] = 'host.com'
|
|
16
|
+
|
|
17
|
+
ServiceClient.username # => 'my-login'
|
|
18
|
+
ServiceClient.hostname # => 'host.com'
|
|
19
|
+
ServiceClient.port # => 80 (default – ENV var not set)
|
|
20
|
+
ServiceClient.password # => nil (ENV var not set, no default)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Type casting
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
class AppConfig
|
|
27
|
+
extend Sinclair::EnvSettable
|
|
28
|
+
|
|
29
|
+
settings_prefix 'APP'
|
|
30
|
+
setting_with_options :timeout, type: :integer, default: 30
|
|
31
|
+
setting_with_options :debug, type: :boolean
|
|
32
|
+
setting_with_options :rate, type: :float
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
ENV['APP_TIMEOUT'] = '60'
|
|
36
|
+
AppConfig.timeout # => 60 (Integer)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
[Back to index](../sinclair-usage.md)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Sinclair::Matchers – RSpec Matchers
|
|
2
|
+
|
|
3
|
+
Include `Sinclair::Matchers` in your RSpec configuration to gain matchers for
|
|
4
|
+
testing that a builder adds or changes methods.
|
|
5
|
+
|
|
6
|
+
### Setup
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
# spec/spec_helper.rb
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.include Sinclair::Matchers
|
|
12
|
+
end
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Available matchers
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
# Checks that build adds an instance method
|
|
19
|
+
expect { builder.build }.to add_method(:name).to(instance)
|
|
20
|
+
expect { builder.build }.to add_method(:name).to(klass)
|
|
21
|
+
|
|
22
|
+
# Checks that build adds a class method
|
|
23
|
+
expect { builder.build }.to add_class_method(:count).to(klass)
|
|
24
|
+
|
|
25
|
+
# Checks that build changes an existing instance method
|
|
26
|
+
expect { builder.build }.to change_method(:value).on(instance)
|
|
27
|
+
|
|
28
|
+
# Checks that build changes an existing class method
|
|
29
|
+
expect { builder.build }.to change_class_method(:count).on(klass)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Example spec
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
RSpec.describe MyBuilder do
|
|
36
|
+
let(:klass) { Class.new }
|
|
37
|
+
let(:instance) { klass.new }
|
|
38
|
+
let(:builder) { MyBuilder.new(klass) }
|
|
39
|
+
|
|
40
|
+
it 'adds a greeting method to instances' do
|
|
41
|
+
expect { builder.build }.to add_method(:greet).to(instance)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'adds a factory class method' do
|
|
45
|
+
expect { builder.build }.to add_class_method(:create).to(klass)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
[Back to index](../sinclair-usage.md)
|