-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from candy-kingdom/feature/32-optional-private…
…-members Add support for including non-public members in the output
- Loading branch information
Showing
12 changed files
with
242 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Summary.Pipes.Filters.FilterMemberPipe | ||
```cs | ||
public class FilterMemberPipe : IPipe<Doc, Doc> | ||
``` | ||
|
||
A simple pipe that filters all members inside the document using the specified predicate. | ||
|
||
## Methods | ||
### Run(Doc) | ||
```cs | ||
public Task<Doc> Run(Doc input) | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Summary.Pipelines.SummaryPipelineExtensions | ||
```cs | ||
public static class SummaryPipelineExtensions | ||
``` | ||
|
||
Convenient extensions for [`SummaryPipeline`](./SummaryPipeline.md). | ||
|
||
## Methods | ||
### UseLoggerFactory(SummaryPipeline, ILoggerFactory) | ||
```cs | ||
public static SummaryPipeline UseLoggerFactory(this SummaryPipeline self, ILoggerFactory factory) | ||
``` | ||
|
||
Specifies the logger factory to use for pipes inside the pipeline. | ||
|
||
_This method should be called _before_ anything else so that_ | ||
_given logger factory is passed into all subsequent calls._ | ||
|
||
### UseDefaultFilters(SummaryPipeline) | ||
```cs | ||
public static SummaryPipeline UseDefaultFilters(this SummaryPipeline self) | ||
``` | ||
|
||
Enables default filters for the given pipeline (i.e. a filter that removes all non-public members). | ||
|
||
### IncludeAtLeast(SummaryPipeline, AccessModifier) | ||
```cs | ||
public static SummaryPipeline IncludeAtLeast(this SummaryPipeline self, AccessModifier access) | ||
``` | ||
|
||
Includes only members that have at least the given access modifier. | ||
|
||
#### Example | ||
In order to include both `internal` and `public` members in the generated docs, | ||
you can call this method as follows: | ||
```cs | ||
var pipeline = ...; | ||
|
||
pipeline.IncludeAtLeast(AccessModifier.Internal); | ||
``` | ||
|
||
### IncludeOnly(SummaryPipeline, AccessModifier) | ||
```cs | ||
public static SummaryPipeline IncludeOnly(this SummaryPipeline self, AccessModifier access) | ||
``` | ||
|
||
Includes only members that have at least the given access modifier. | ||
|
||
#### Example | ||
In order to include onl `internal` members in the generated docs, | ||
you can call this method as follows: | ||
```cs | ||
var pipeline = ...; | ||
|
||
pipeline.IncludeOnly(AccessModifier.Internal); | ||
``` | ||
|
||
### UseFilter(SummaryPipeline, IPipe<Doc, Doc>) | ||
```cs | ||
public static SummaryPipeline UseFilter(this SummaryPipeline self, IPipe<Doc, Doc> filter) | ||
``` | ||
|
||
Adds the given filter into the pipeline. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Summary.Pipes; | ||
using Summary.Pipes.Filters; | ||
|
||
namespace Summary.Pipelines; | ||
|
||
/// <summary> | ||
/// Convenient extensions for <see cref="SummaryPipeline"/>. | ||
/// </summary> | ||
public static class SummaryPipelineExtensions | ||
{ | ||
/// <summary> | ||
/// Specifies the logger factory to use for pipes inside the pipeline. | ||
/// </summary> | ||
/// <remarks> | ||
/// This method should be called <i>before</i> anything else so that | ||
/// given logger factory is passed into all subsequent calls. | ||
/// </remarks> | ||
public static SummaryPipeline UseLoggerFactory(this SummaryPipeline self, ILoggerFactory factory) => | ||
self.Customize(options => options.UseLoggerFactory(factory)); | ||
|
||
/// <summary> | ||
/// Enables default filters for the given pipeline (i.e. a filter that removes all non-public members). | ||
/// </summary> | ||
public static SummaryPipeline UseDefaultFilters(this SummaryPipeline self) => self | ||
.IncludeOnly(AccessModifier.Public); | ||
|
||
/// <summary> | ||
/// Includes only members that have at least the given access modifier. | ||
/// </summary> | ||
/// <example> | ||
/// In order to include both <c>internal</c> and <c>public</c> members in the generated docs, | ||
/// you can call this method as follows: | ||
/// <para><code> | ||
/// var pipeline = ...; | ||
/// | ||
/// pipeline.IncludeAtLeast(AccessModifier.Internal); | ||
/// </code></para> | ||
/// </example> | ||
public static SummaryPipeline IncludeAtLeast(this SummaryPipeline self, AccessModifier access) => self | ||
.UseFilter(new FilterMemberPipe(x => x.Access >= access)); | ||
|
||
/// <summary> | ||
/// Includes only members that have at least the given access modifier. | ||
/// </summary> | ||
/// <example> | ||
/// In order to include onl <c>internal</c> members in the generated docs, | ||
/// you can call this method as follows: | ||
/// <para><code> | ||
/// var pipeline = ...; | ||
/// | ||
/// pipeline.IncludeOnly(AccessModifier.Internal); | ||
/// </code></para> | ||
/// </example> | ||
public static SummaryPipeline IncludeOnly(this SummaryPipeline self, AccessModifier access) => self | ||
.UseFilter(new FilterMemberPipe(x => x.Access == access)); | ||
|
||
/// <summary> | ||
/// Adds the given filter into the pipeline. | ||
/// </summary> | ||
/// <seealso cref="SummaryPipeline.Filters"/> | ||
public static SummaryPipeline UseFilter(this SummaryPipeline self, IPipe<Doc, Doc> filter) | ||
{ | ||
self.Filters.Add(filter); | ||
return self; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Summary.Pipes.Filters; | ||
|
||
/// <summary> | ||
/// A simple pipe that filters all members inside the document using the specified predicate. | ||
/// </summary> | ||
public class FilterMemberPipe : IPipe<Doc, Doc> | ||
{ | ||
private readonly Predicate<DocMember> _p ; | ||
|
||
public FilterMemberPipe(Predicate<DocMember> p) => | ||
Check warning on line 10 in src/Core/Pipes/Filters/FilterMemberPipe.cs GitHub Actions / build
|
||
_p = p; | ||
|
||
public Task<Doc> Run(Doc input) => | ||
Check warning on line 13 in src/Core/Pipes/Filters/FilterMemberPipe.cs GitHub Actions / build
|
||
Task.FromResult(new Doc(Filtered(input.Members))); | ||
|
||
private DocMember[] Filtered(DocMember[] members) => | ||
members | ||
.Where(x => _p(x)) | ||
.Select(Filtered) | ||
.ToArray(); | ||
|
||
private DocMember Filtered(DocMember member) => member switch | ||
{ | ||
DocTypeDeclaration type => type with { Members = Filtered(type.Members) }, | ||
|
||
_ => member, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.