+19
−11
Loading
- Refactor Matcher from `Data.define(...) do ... end` block form to
`class Matcher < Data.define(:type, :value); end` so internal
constants (KNOWN_HASH_KEYS, MAX_REGEX_SOURCE_LENGTH, the new
ERROR_INSPECT_LIMIT) live inside the class instead of polluting
the surrounding RateLimit namespace. Removes the now-redundant
module-level MATCHER_KNOWN_HASH_KEYS / MATCHER_MAX_REGEX_SOURCE_LENGTH.
- Drop the `# @api private` line — the codebase doesn't use that
convention.
- Add an explicit `else raise ArgumentError, "unknown matcher type:
..."` arm to `Matcher#match?` so a hand-constructed
`Matcher.new(type: :glob, ...)` (bypassing `.build`) explodes loudly
on first use rather than silently returning nil.
- Add `Matcher.truncate_for_error` private helper and apply it to the
three rejection branches (Array, multi-key Hash, unknown type key).
Bounds the resulting `ArgumentError` message length, defending
against multi-megabyte garbage inputs reaching logs / error
trackers. Regex-source branches already capped at 200 chars.
- Test name rebuild: drop "Spec 10 / Scenario X:" prefixes from
describe / context / it strings across matcher_spec, rule_spec, and
evaluator_spec. Tests now describe behaviour, not their position in
the spec.
- Restructure evaluator_spec's regex blocks into behaviour-named
describes ("with an :equality matcher", "with a :regex matcher",
"when the rule has multiple match keys"); fold counter-key,
no-match-falls-through, and quiet-skip cases into the regex
describe as it/contexts of the same code path.
- Add spec coverage for the new bypass guard and the bounded-error
helper (Array / unknown-type-key / multi-key-Hash).
Co-Authored-By:
Claude Opus 4.7 (1M context) <noreply@anthropic.com>