Skip to content

Commit e9f1aa9

Browse files
committed
make entitlement weight a method on the enum
1 parent 41c2726 commit e9f1aa9

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
@@ -35,9 +35,9 @@ const (
3535
EntitlementNotEntitled Entitlement = "not_entitled"
3636
)
3737

38-
// entitlementWeight converts the enum types to a numerical value for easier
38+
// Weight converts the enum types to a numerical value for easier
3939
// comparisons. Easier than sets of if statements.
40-
func entitlementWeight(e Entitlement) int {
40+
func (e Entitlement) Weight() int {
4141
switch e {
4242
case EntitlementEntitled:
4343
return 2
@@ -194,7 +194,7 @@ func CompareFeatures(a, b Feature) int {
194194
// feature can be "greater" than an entitled.
195195
// If either is "NotEntitled" then we can defer to a strict entitlement
196196
// check.
197-
if entitlementWeight(a.Entitlement) >= 0 && entitlementWeight(b.Entitlement) >= 0 {
197+
if a.Entitlement.Weight() >= 0 && b.Entitlement.Weight() >= 0 {
198198
if a.Capable() && !b.Capable() {
199199
return 1
200200
}
@@ -205,7 +205,7 @@ func CompareFeatures(a, b Feature) int {
205205
}
206206

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

0 commit comments

Comments
 (0)