Skip to content

Commit

Permalink
make more things internal and switch some stuff to use IEphemeralMeta…
Browse files Browse the repository at this point in the history
…data over the concrete
  • Loading branch information
Confusingboat committed Jun 2, 2023
1 parent bf53733 commit 2850d95
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/Ephemerally.Azure.Cosmos/InternalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Ephemerally.Azure.Cosmos;

internal static class InternalExtensions
{
internal static T OrDefault<T>(this T options) where T : EphemeralOptions, new() =>
options ?? new T();

internal static async Task<bool> ExistsAsync(this Database database) =>
await database.Client.DatabaseExistsAsync(database.Id).ConfigureAwait(false);

Expand Down
8 changes: 4 additions & 4 deletions src/Ephemerally.Azure.Cosmos/PublicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public static async Task<EphemeralCosmosContainer> CreateEphemeralContainerAsync
return database.GetContainer(response.Resource.Id).ToEphemeral(options);
}

public static EphemeralMetadata GetEphemeralMetadata(this DatabaseProperties container) =>
public static IEphemeralMetadata GetEphemeralMetadata(this DatabaseProperties container) =>
container.Id.GetContainerMetadata();

public static EphemeralMetadata GetEphemeralMetadata(this Database container) =>
public static IEphemeralMetadata GetEphemeralMetadata(this Database container) =>
container.Id.GetContainerMetadata();

public static EphemeralMetadata GetEphemeralMetadata(this ContainerProperties container) =>
public static IEphemeralMetadata GetEphemeralMetadata(this ContainerProperties container) =>
container.Id.GetContainerMetadata();

public static EphemeralMetadata GetEphemeralMetadata(this Container container) =>
public static IEphemeralMetadata GetEphemeralMetadata(this Container container) =>
container.Id.GetContainerMetadata();
}
13 changes: 13 additions & 0 deletions src/Ephemerally/InternalExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ephemerally;

internal static class InternalExtensions
{
internal static T OrDefault<T>(this T options) where T : EphemeralOptions, new() =>
options ?? new T();
}
16 changes: 5 additions & 11 deletions src/Ephemerally/PublicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

public static class PublicExtensions
{
//public static EphemeralCreationOptions OrDefault(this EphemeralCreationOptions options) =>
// options ?? EphemeralCreationOptions.Default;

public static T OrDefault<T>(this T options) where T : EphemeralOptions, new() =>
options ?? new T();

public static EphemeralMetadata GetNewMetadata(this EphemeralCreationOptions options) =>
public static IEphemeralMetadata GetNewMetadata(this EphemeralCreationOptions options) =>
EphemeralMetadata.New(options.Name, options.GetExpiration(DateTimeOffset.UtcNow));

public static bool IsExpired(this EphemeralMetadata metadata) =>
IsExpired(metadata, DateTimeOffset.UtcNow);
public static bool IsExpired(this IEphemeralMetadata metadata) =>
IsExpiredAsOf(metadata, DateTimeOffset.UtcNow);

internal static bool IsExpired(this EphemeralMetadata metadata, DateTimeOffset now) =>
public static bool IsExpiredAsOf(this IEphemeralMetadata metadata, DateTimeOffset now) =>
metadata.Expiration.HasValue && metadata.Expiration.Value <= now;

public static EphemeralMetadata GetContainerMetadata(this string fullName) =>
public static IEphemeralMetadata GetContainerMetadata(this string fullName) =>
EphemeralMetadata.New(fullName);
}
2 changes: 1 addition & 1 deletion tests/Ephemerally.Tests/EphemeralMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public bool IsExpired_as_of_1684991963(long now)
Nonce = "ABCDEF"
};

return metadata.IsExpired(DateTimeOffset.FromUnixTimeSeconds(now));
return metadata.IsExpiredAsOf(DateTimeOffset.FromUnixTimeSeconds(now));
}
}

0 comments on commit 2850d95

Please sign in to comment.