You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.TrashLib/Config/Parsing/PostProcessing/ConfigMerging/TemplateIncludeProcessor.cs

43 lines
1.3 KiB

using System.IO.Abstractions;
using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Config.Parsing.PostProcessing.ConfigMerging;
public class TemplateIncludeProcessor : IIncludeProcessor
{
private readonly IConfigTemplateGuideService _templates;
public TemplateIncludeProcessor(IConfigTemplateGuideService templates)
{
_templates = templates;
}
public bool CanProcess(IYamlInclude includeDirective)
{
return includeDirective is TemplateYamlInclude;
}
public IFileInfo GetPathToConfig(IYamlInclude includeDirective, SupportedServices serviceType)
{
var include = (TemplateYamlInclude) includeDirective;
if (include.Template is null)
{
throw new YamlIncludeException("`template` property is required.");
}
var includePath = _templates.GetIncludeData()
.Where(x => x.Service == serviceType)
.FirstOrDefault(x => x.Id.EqualsIgnoreCase(include.Template));
if (includePath is null)
{
throw new YamlIncludeException(
$"For service type '{serviceType}', unable to find config template with name '{include.Template}'");
}
return includePath.TemplateFile;
}
}