/
FileLinkOptionalSettingsBuilder.cs
53 lines (46 loc) · 1.74 KB
/
FileLinkOptionalSettingsBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace Cake.Issues.FileLinking
{
using System;
using System.Collections.Generic;
/// <summary>
/// Class containing builder for optional settings for linking to files.
/// </summary>
public class FileLinkOptionalSettingsBuilder : FileLinkSettings
{
private readonly Func<IIssue, IDictionary<string, string>, Uri> builder;
/// <summary>
/// Initializes a new instance of the <see cref="FileLinkOptionalSettingsBuilder"/> class.
/// </summary>
/// <param name="builder">Callback called for building the file link.</param>
internal FileLinkOptionalSettingsBuilder(Func<IIssue, IDictionary<string, string>, Uri> builder)
: base(builder)
{
builder.NotNull(nameof(builder));
this.builder = builder;
}
/// <summary>
/// Sets the root path for the files.
/// </summary>
/// <param name="rootPath">Root path for the files.
/// <c>null</c> if files are in the root of the repository.</param>
/// <returns>Object for creating the file link.</returns>
public FileLinkSettings WithRootPath(string rootPath)
{
if (rootPath != null)
{
rootPath.NotNullOrWhiteSpace(nameof(rootPath));
if (!rootPath.IsValidPath())
{
throw new ArgumentException($"Invalid path '{rootPath}'", nameof(rootPath));
}
}
return
new FileLinkSettings(
(issue, values) =>
{
values.Add("rootPath", rootPath);
return this.builder(issue, values);
});
}
}
}