Skip to content

Commit bf6d317

Browse files
committed
Make public the class EnumWithValue
1 parent d77611f commit bf6d317

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

lib/src/common/model/checks.dart

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
1+
import 'package:github/src/common/util/utils.dart';
12
import 'package:github/src/util.dart';
23
import 'package:meta/meta.dart';
34

4-
@immutable
5-
abstract class _EnumWithValue {
6-
final String _jsonValue;
7-
const _EnumWithValue._(this._jsonValue);
8-
9-
@override
10-
String toString() => _jsonValue;
11-
12-
String toJson() => _jsonValue;
13-
14-
@override
15-
bool operator ==(dynamic other) =>
16-
other is _EnumWithValue && _jsonValue == other._jsonValue;
17-
18-
@override
19-
int get hashCode => _jsonValue.hashCode;
20-
}
21-
22-
class CheckRunAnnotationLevel extends _EnumWithValue {
5+
class CheckRunAnnotationLevel extends EnumWithValue {
236
static const notice = CheckRunAnnotationLevel._('notice');
247
static const warning = CheckRunAnnotationLevel._('warning');
258
static const failure = CheckRunAnnotationLevel._('failure');
269

27-
const CheckRunAnnotationLevel._(String value) : super._(value);
10+
const CheckRunAnnotationLevel._(String value) : super(value);
2811

2912
factory CheckRunAnnotationLevel._fromValue(String value) {
3013
switch (value) {
@@ -56,15 +39,15 @@ class CheckRunAnnotationLevel extends _EnumWithValue {
5639
bool operator >=(CheckRunAnnotationLevel other) => !(this < other);
5740
}
5841

59-
class CheckRunConclusion extends _EnumWithValue {
42+
class CheckRunConclusion extends EnumWithValue {
6043
static const success = CheckRunConclusion._('success');
6144
static const failure = CheckRunConclusion._('failure');
6245
static const neutral = CheckRunConclusion._('neutral');
6346
static const cancelled = CheckRunConclusion._('cancelled');
6447
static const timedOut = CheckRunConclusion._('timed_out');
6548
static const actionRequired = CheckRunConclusion._('action_required');
6649

67-
const CheckRunConclusion._(String value) : super._(value);
50+
const CheckRunConclusion._(String value) : super(value);
6851

6952
factory CheckRunConclusion._fromValue(String value) {
7053
for (final level in const [
@@ -75,7 +58,7 @@ class CheckRunConclusion extends _EnumWithValue {
7558
timedOut,
7659
actionRequired
7760
]) {
78-
if (level._jsonValue == value) {
61+
if (level.value == value) {
7962
return level;
8063
}
8164
}
@@ -84,17 +67,17 @@ class CheckRunConclusion extends _EnumWithValue {
8467
}
8568
}
8669

87-
class CheckRunStatus extends _EnumWithValue {
70+
class CheckRunStatus extends EnumWithValue {
8871
static const queued = CheckRunStatus._('queued');
8972
static const inProgress = CheckRunStatus._('in_progress');
9073
static const completed = CheckRunStatus._('completed');
91-
const CheckRunStatus._(String value) : super._(value);
74+
const CheckRunStatus._(String value) : super(value);
9275
}
9376

94-
class CheckRunFilter extends _EnumWithValue {
77+
class CheckRunFilter extends EnumWithValue {
9578
static const all = CheckRunFilter._('all');
9679
static const latest = CheckRunFilter._('latest');
97-
const CheckRunFilter._(String value) : super._(value);
80+
const CheckRunFilter._(String value) : super(value);
9881
}
9982

10083
@immutable

lib/src/common/util/utils.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
import 'package:github/src/common.dart';
22
import 'package:github/src/util.dart';
3+
import 'package:meta/meta.dart';
4+
5+
/// A Json encodable class that mimics an enum,
6+
/// but with a String value that is used for serialization.
7+
@immutable
8+
abstract class EnumWithValue {
9+
final String value;
10+
11+
/// The value will be used when [toJson] or [toString] will be called.
12+
/// It will also be used to check if two [EnumWithValue] are equal.
13+
const EnumWithValue(this.value);
14+
15+
@override
16+
String toString() => value;
17+
18+
/// Returns the String value of this.
19+
String toJson() => value;
20+
21+
/// True iff [other] is an [EnumWithValue] with the same value as this object.
22+
@override
23+
bool operator ==(dynamic other) =>
24+
other is EnumWithValue && value == other.value;
25+
26+
@override
27+
int get hashCode => value.hashCode;
28+
}
329

430
/// Marks something as not being ready or complete.
531
class NotReadyYet {
@@ -21,7 +47,9 @@ class OnlyWhen {
2147
///
2248
/// The format is "YYYY-MM-DDTHH:mm:ssZ"
2349
String dateToGitHubIso8601(DateTime date) {
24-
if (date == null) return null;
50+
if (date == null) {
51+
return null;
52+
}
2553
// Regex removes the milliseconds.
2654
return date.toUtc().toIso8601String().replaceAll(githubDateRemoveRegExp, '');
2755
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy