Skip to content

Instantly share code, notes, and snippets.

@nbevans
Created February 8, 2013 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbevans/4737222 to your computer and use it in GitHub Desktop.
Save nbevans/4737222 to your computer and use it in GitHub Desktop.
Idea for CorrugatedIron's Links API
internal static class RiakObjectExtensions {
/// <summary>
/// Creates (or updates) a link to point to the designated object.
/// </summary>
/// <param name="ro">The Riak object whose link will be created or updated.</param>
/// <param name="riakObjectId">The Riak object identifier to be linked to.</param>
/// <param name="tag">The tag (or name) of the link.</param>
public static void SingleLinkTo(this RiakObject ro, RiakObjectId riakObjectId, string tag) {
SingleLinkTo(ro, riakObjectId.Bucket, riakObjectId.Key, tag);
}
/// <summary>
/// Creates (or updates) a link to point to the designated object.
/// </summary>
/// <param name="ro">The Riak object whose link will be created or updated.</param>
/// <param name="riakObject">The Riak object to be linked to.</param>
/// <param name="tag">The tag (or name) of the link.</param>
public static void SingleLinkTo(this RiakObject ro, RiakObject riakObject, string tag) {
SingleLinkTo(ro, riakObject.Bucket, riakObject.Key, tag);
}
/// <summary>
/// Creates (or updates) a link to point to the designated object.
/// </summary>
/// <param name="ro">The Riak object whose link will be created or updated.</param>
/// <param name="bucket">The bucket of the object to be linked to.</param>
/// <param name="key">The key of the object to be linked to.</param>
/// <param name="tag">The tag (or name) of the link.</param>
public static void SingleLinkTo(this RiakObject ro, string bucket, string key, string tag) {
var link = ro.Links.SingleOrDefault(l => l.Tag.Equals(tag));
if (link != null)
ro.RemoveLink(link);
ro.LinkTo(bucket, key, tag);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment