Skip to content

Commit

Permalink
Wrap all construction into factory method instead of extending class
Browse files Browse the repository at this point in the history
  • Loading branch information
rk0cc committed Jan 18, 2024
1 parent f84ccee commit 96701a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 4 additions & 0 deletions model/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.4.0

* Add `MockOgHrefClient.advance` for building responding content with different content type applied.

## 3.3.4

* Restrict `MockOgHrefClient` accepted requesting `GET` and `HEAD` method.
Expand Down
25 changes: 10 additions & 15 deletions model/lib/src/client/mock_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ final class MockOgHrefClient extends BaseClient
/// * [MockOgHrefClient.quick] : Quick builder version of [MockOgHrefClient]
/// that [Uri]s are mapping with [String] content with unified
/// content type.
MockOgHrefClient(Map<Uri, MockOgHrefClientContent> contentLinker,
MockOgHrefClient.advance(Map<Uri, MockOgHrefClientContent> contentLinker,
{String errorContentType = _PLAIN_TEXT_MIME}) {
if (contentLinker.keys.any((element) => !_isHttpScheme(element))) {
throw ArgumentError(
Expand Down Expand Up @@ -235,14 +235,19 @@ final class MockOgHrefClient extends BaseClient
/// [contentType] which uses `text/plain` as default.
///
/// For setting [contentLinker] without identical [contentType],
/// please uses [MockOgHrefClient.new] instead.
factory MockOgHrefClient.quick(Map<Uri, String> contentLinker,
{String contentType}) = _QuickMockOgHrefClient;
/// please uses [MockOgHrefClient.advance] instead.
factory MockOgHrefClient(Map<Uri, String> contentLinker,
{String contentType = _PLAIN_TEXT_MIME}) {
return MockOgHrefClient.advance({
for (var MapEntry(key: url, value: body) in contentLinker.entries)
url: MockOgHrefClientContent(content: body, contentType: contentType)
});
}

/// Uses [sample files](https://github.com/rk0cc/oghref/tree/main/model/sample) to defined
/// content of the simulated HTML files with hosted IP address as `127.0.0.2` with `HTTPS`
/// protocol.
factory MockOgHrefClient.usesSample() => _QuickMockOgHrefClient(<Uri, String>{
factory MockOgHrefClient.usesSample() => MockOgHrefClient(<Uri, String>{
for (int idx = 0; idx < _sampleContents.length; idx++)
_sampleMockHost.resolve("${idx + 1}.html"): _sampleContents[idx]
});
Expand All @@ -264,13 +269,3 @@ final class MockOgHrefClient extends BaseClient
return _c.send(request).timeout(Duration(seconds: OgHrefClient.timeoutAt));
}
}

final class _QuickMockOgHrefClient extends MockOgHrefClient {
_QuickMockOgHrefClient(Map<Uri, String> contentLinker,
{String contentType = "text/plain"})
: super({
for (var MapEntry(key: url, value: body) in contentLinker.entries)
url:
MockOgHrefClientContent(content: body, contentType: contentType)
});
}
2 changes: 1 addition & 1 deletion model/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: oghref_model
description: Object standarized definition with parser interface for constructing rich information of given URL among various metadata protocols.
version: 3.3.4
version: 3.4.0
repository: https://github.com/rk0cc/oghref/tree/main/model
issue_tracker: https://github.com/rk0cc/oghref/issues
funding:
Expand Down

0 comments on commit 96701a7

Please sign in to comment.