-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce strongly-typed Relic Address (#24)
- Loading branch information
Showing
77 changed files
with
278 additions
and
1,778 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
include: package:lints/recommended.yaml | ||
|
||
linter: | ||
rules: | ||
- avoid_dynamic_calls | ||
- unawaited_futures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'dart:io'; | ||
|
||
/// A class that represents an address. | ||
abstract final class RelicAddress<T> { | ||
/// Returns the address as an [Object]. | ||
T get address; | ||
|
||
/// Creates a [RelicAddress] from a [String]. | ||
static RelicAddress<String> fromHostname(String hostname) { | ||
return _RelicHostnameAddress(hostname: hostname); | ||
} | ||
|
||
/// Creates a [RelicAddress] from an [InternetAddress]. | ||
static RelicAddress<InternetAddress> fromInternetAddress( | ||
InternetAddress address, | ||
) { | ||
return _RelicInternetAddress(internetAddress: address); | ||
} | ||
} | ||
|
||
/// A class that represents a hostname address. | ||
final class _RelicHostnameAddress implements RelicAddress<String> { | ||
/// The hostname of the address. | ||
final String hostname; | ||
|
||
_RelicHostnameAddress({ | ||
required this.hostname, | ||
}); | ||
|
||
/// Returns the address as a [String]. | ||
@override | ||
String get address => hostname; | ||
|
||
@override | ||
String toString() => 'RelicHostnameAddress(hostname: $hostname)'; | ||
} | ||
|
||
/// A class that represents an internet address. | ||
final class _RelicInternetAddress implements RelicAddress<InternetAddress> { | ||
/// The internet address of the address. | ||
final InternetAddress internetAddress; | ||
|
||
_RelicInternetAddress({ | ||
required this.internetAddress, | ||
}); | ||
|
||
/// Returns the address as an [InternetAddress]. | ||
@override | ||
InternetAddress get address => internetAddress; | ||
|
||
@override | ||
String toString() => | ||
'RelicInternetAddress(internetAddress: $internetAddress)'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.