Skip to content

feat(feature): add NewBooleanGate convenience constructor#144

Merged
sourcehawk merged 1 commit into
mainfrom
feature/boolean-gate
Jun 1, 2026
Merged

feat(feature): add NewBooleanGate convenience constructor#144
sourcehawk merged 1 commit into
mainfrom
feature/boolean-gate

Conversation

@sourcehawk
Copy link
Copy Markdown
Owner

Description

Adds feature.NewBooleanGate(enabled bool), a convenience constructor for a gate driven purely by a boolean. It is shorthand for feature.NewVersionGate("", nil).When(enabled), the form operators reach for whenever a mutation or resource is toggled by a spec flag rather than an application version. The explicit empty-version spelling is easy to mistype and reads obscurely, so this gives that common case a direct, well-named constructor.

Changes

  • Add feature.NewBooleanGate(enabled bool) *VersionGate: a gate with no version constraints whose result is driven solely by the boolean. It returns *VersionGate, so additional conditions still compose via When.

Related

Documentation and examples adopt the new constructor separately, on the docs site branch.

Testing

New table tests cover the enabled and disabled results and confirm that further When conditions still compose on the returned gate. go test ./pkg/feature/... passes, and go build ./..., make build-examples, and golangci-lint run ./pkg/feature/... (0 issues) are all clean.

NewBooleanGate(enabled) is shorthand for NewVersionGate("", nil).When(enabled):
a gate with no version constraints whose result is driven solely by a boolean.
It expresses flag-toggled mutations and resources more directly than spelling out
an empty version gate, and still returns a *VersionGate so further conditions
compose with When.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 1, 2026 23:11
@sourcehawk sourcehawk merged commit 6806405 into main Jun 1, 2026
4 checks passed
@sourcehawk sourcehawk deleted the feature/boolean-gate branch June 1, 2026 23:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a small convenience constructor feature.NewBooleanGate(enabled bool) that wraps the common NewVersionGate("", nil).When(enabled) pattern, with accompanying unit tests.

Changes:

  • New exported NewBooleanGate constructor in pkg/feature/feature.go.
  • Table-driven tests plus a chaining test verifying composition with When.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/feature/feature.go Adds NewBooleanGate shorthand returning *VersionGate.
pkg/feature/feature_test.go Adds enabled/disabled table tests and a chainability test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants