Skip to content

Commit e06b434

Browse files
committed
make entitlement weight a method on the enum
1 parent 7436159 commit e06b434

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

codersdk/deployment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const (
3434
EntitlementNotEntitled Entitlement = "not_entitled"
3535
)
3636

37-
// entitlementWeight converts the enum types to a numerical value for easier
37+
// Weight converts the enum types to a numerical value for easier
3838
// comparisons. Easier than sets of if statements.
39-
func entitlementWeight(e Entitlement) int {
39+
func (e Entitlement) Weight() int {
4040
switch e {
4141
case EntitlementEntitled:
4242
return 2
@@ -193,7 +193,7 @@ func CompareFeatures(a, b Feature) int {
193193
// feature can be "greater" than an entitled.
194194
// If either is "NotEntitled" then we can defer to a strict entitlement
195195
// check.
196-
if entitlementWeight(a.Entitlement) >= 0 && entitlementWeight(b.Entitlement) >= 0 {
196+
if a.Entitlement.Weight() >= 0 && b.Entitlement.Weight() >= 0 {
197197
if a.Capable() && !b.Capable() {
198198
return 1
199199
}
@@ -204,7 +204,7 @@ func CompareFeatures(a, b Feature) int {
204204
}
205205

206206
// Strict entitlement check. Higher is better
207-
entitlementDifference := entitlementWeight(a.Entitlement) - entitlementWeight(b.Entitlement)
207+
entitlementDifference := a.Entitlement.Weight() - b.Entitlement.Weight()
208208
if entitlementDifference != 0 {
209209
return entitlementDifference
210210
}

0 commit comments

Comments
 (0)