Skip to content

Commit

Permalink
Merge pull request #370 from gregsdennis/logic/rule-accessibility
Browse files Browse the repository at this point in the history
update version and release notes
  • Loading branch information
gregsdennis committed Jan 23, 2023
2 parents 32bb311 + 32292a1 commit 235fa3f
Show file tree
Hide file tree
Showing 37 changed files with 454 additions and 104 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# https://github.com/actions/labeler

name: Labeler
on: [pull_request]
on: [pull_request_target]

jobs:
label:

permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest

steps:
- uses: actions/labeler@v4
with:
Expand Down
2 changes: 0 additions & 2 deletions JsonLogic.Tests/AddTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Json.Logic.Rules;
using Json.More;
using NUnit.Framework;

namespace Json.Logic.Tests;
Expand Down
4 changes: 2 additions & 2 deletions JsonLogic/JsonLogic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<PackageTags>json logic json-logic jsonlogic</PackageTags>
<PackageReleaseNotes>Release notes can be found on [GitHub](https://github.com/gregsdennis/json-everything/blob/master/json-everything.net/wwwroot/md/release-notes/json-logic.md) and https://json-everything.net/json-logic</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.2.0</Version>
<Version>3.3.0</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.2.0.0</FileVersion>
<FileVersion>3.3.0.0</FileVersion>
<DocumentationFile>JsonLogic.xml</DocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
12 changes: 10 additions & 2 deletions JsonLogic/Rules/AddRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(AddRuleJsonConverter))]
public class AddRule : Rule
{
internal List<Rule> Items { get; }
/// <summary>
/// The sequence of values to add together.
/// </summary>
protected internal List<Rule> Items { get; }

internal AddRule(Rule a, params Rule[] more)
/// <summary>
/// Creates a new instance of <see cref="AddRule"/> when '+' operator is detected within json logic.
/// </summary>
/// <param name="a">The first value, to which other values will be added to.</param>
/// <param name="more">Sequence of values to add to the first value.</param>
protected internal AddRule(Rule a, params Rule[] more)
{
Items = new List<Rule> { a };
Items.AddRange(more);
Expand Down
18 changes: 15 additions & 3 deletions JsonLogic/Rules/AllRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(AllRuleJsonConverter))]
public class AllRule : Rule
{
internal Rule Input { get; }
internal Rule Rule { get; }
/// <summary>
/// The sequence of elements to apply the rule to.
/// </summary>
protected internal Rule Input { get; }

/// <summary>
/// The rule to apply to All items in the input sequence.
/// </summary>
protected internal Rule Rule { get; }

internal AllRule(Rule input, Rule rule)
/// <summary>
/// Creates a new instance of <see cref="AllRule"/> when 'all' operator is detected within json logic.
/// </summary>
/// <param name="input">A sequence of elements to apply the rule to.</param>
/// <param name="rule">A rule to apply to All items in the input sequence.</param>
protected internal AllRule(Rule input, Rule rule)
{
Input = input;
Rule = rule;
Expand Down
12 changes: 10 additions & 2 deletions JsonLogic/Rules/AndRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(AndRuleJsonConverter))]
public class AndRule : Rule
{
internal List<Rule> Items { get; }
/// <summary>
/// The sequence of values to And against.
/// </summary>
protected internal List<Rule> Items { get; }

internal AndRule(Rule a, params Rule[] more)
/// <summary>
/// Creates a new instance of <see cref="AndRule"/> when 'and' operator is detected within json logic.
/// </summary>
/// <param name="a">The first value.</param>
/// <param name="more">Sequence of values to And against.</param>
protected internal AndRule(Rule a, params Rule[] more)
{
Items = new List<Rule> { a };
Items.AddRange(more);
Expand Down
13 changes: 9 additions & 4 deletions JsonLogic/Rules/BooleanCastRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(BooleanCastRuleJsonConverter))]
public class BooleanCastRule : Rule
{
internal Rule Value { get; }
/// <summary>
/// The value to test.
/// </summary>
protected internal Rule Value { get; }

internal BooleanCastRule(Rule value)
/// <summary>
/// Creates a new instance of <see cref="BooleanCastRule"/> when '!!' operator is detected within json logic.
/// </summary>
/// <param name="value">The value to test.</param>
protected internal BooleanCastRule(Rule value)
{
Value = value;
}
Expand All @@ -30,8 +37,6 @@ internal BooleanCastRule(Rule value)
/// <returns>The result of the rule.</returns>
public override JsonNode? Apply(JsonNode? data, JsonNode? contextData = null)
{
var value = Value.Apply(data, contextData);

return Value.Apply(data, contextData).IsTruthy();
}
}
Expand Down
12 changes: 10 additions & 2 deletions JsonLogic/Rules/CatRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(CatRuleJsonConverter))]
public class CatRule : Rule
{
internal List<Rule> Items { get; }
/// <summary>
/// The sequence of values to concatenate together.
/// </summary>
protected internal List<Rule> Items { get; }

internal CatRule(Rule a, params Rule[] more)
/// <summary>
/// Creates a new instance of <see cref="CatRule"/> when 'cat' operator is detected within json logic.
/// </summary>
/// <param name="a">The first value, to which subsequent values will be concatenated to.</param>
/// <param name="more">A sequence of values to concatenate to the first value.</param>
protected internal CatRule(Rule a, params Rule[] more)
{
Items = new List<Rule> { a };
Items.AddRange(more);
Expand Down
17 changes: 14 additions & 3 deletions JsonLogic/Rules/DivideRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(DivideRuleJsonConverter))]
public class DivideRule : Rule
{
internal Rule A { get; }
internal Rule B { get; }
/// <summary>
/// The value to divide.
/// </summary>
protected internal Rule A { get; }
/// <summary>
/// The divisor.
/// </summary>
protected internal Rule B { get; }

internal DivideRule(Rule a, Rule b)
/// <summary>
/// Creates a new instance of <see cref="DivideRule"/> when '/' operator is detected within json logic.
/// </summary>
/// <param name="a">The value to divide.</param>
/// <param name="b">The divisor, ie; the value to divide by.</param>
protected internal DivideRule(Rule a, Rule b)
{
A = a;
B = b;
Expand Down
18 changes: 15 additions & 3 deletions JsonLogic/Rules/FilterRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(FilterRuleJsonConverter))]
public class FilterRule : Rule
{
internal Rule Input { get; }
internal Rule Rule { get; }
/// <summary>
/// A sequence of values to filter.
/// </summary>
protected internal Rule Input { get; }

/// <summary>
/// A predicate to apply to each item in the sequence.
/// </summary>
protected internal Rule Rule { get; }

internal FilterRule(Rule input, Rule rule)
/// <summary>
/// Creates a new instance of <see cref="FilterRule"/> when 'filter' operator is detected within json logic.
/// </summary>
/// <param name="input">A sequence of values to filter.</param>
/// <param name="rule">A predicate to apply to each item in the sequence.</param>
protected internal FilterRule(Rule input, Rule rule)
{
Input = input;
Rule = rule;
Expand Down
11 changes: 9 additions & 2 deletions JsonLogic/Rules/IfRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(IfRuleJsonConverter))]
public class IfRule : Rule
{
internal List<Rule> Components { get; }
/// <summary>
/// A condition, what to do when the condition is true, and what to do when the condition is false.
/// </summary>
protected internal List<Rule> Components { get; }

internal IfRule(params Rule[] components)
/// <summary>
/// Creates a new instance of <see cref="IfRule"/> when 'if' or '?:' operators are detected within json logic.
/// </summary>
/// <param name="components">A condition, what to do when the condition is true, and what to do when the condition is false.</param>
protected internal IfRule(params Rule[] components)
{
Components = new List<Rule>(components);
}
Expand Down
25 changes: 18 additions & 7 deletions JsonLogic/Rules/InRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(InRuleJsonConverter))]
public class InRule : Rule
{
internal Rule Test { get; }
internal Rule Source { get; }
/// <summary>
/// A value to search for.
/// </summary>
protected internal Rule Test { get; }
/// <summary>
/// The string value to test against.
/// </summary>
protected internal Rule Value { get; }

internal InRule(Rule test, Rule source)
/// <summary>
/// Creates a new instance of <see cref="InRule"/> when 'in' operator is detected within json logic.
/// </summary>
/// <param name="test">A value to search for.</param>
/// <param name="value">The string value to test against.</param>
protected internal InRule(Rule test, Rule value)
{
Test = test;
Source = source;
Value = value;
}

/// <summary>
Expand All @@ -35,7 +46,7 @@ internal InRule(Rule test, Rule source)
public override JsonNode? Apply(JsonNode? data, JsonNode? contextData = null)
{
var test = Test.Apply(data, contextData);
var source = Source.Apply(data, contextData);
var source = Value.Apply(data, contextData);

if (source is JsonValue value && value.TryGetValue(out string? stringSource))
{
Expand Down Expand Up @@ -72,8 +83,8 @@ public override void Write(Utf8JsonWriter writer, InRule value, JsonSerializerOp
writer.WritePropertyName("in");
writer.WriteStartArray();
writer.WriteRule(value.Test, options);
writer.WriteRule(value.Source, options);
writer.WriteRule(value.Value, options);
writer.WriteEndArray();
writer.WriteEndObject();
}
}
}
30 changes: 25 additions & 5 deletions JsonLogic/Rules/LessThanEqualRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,36 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(LessThanEqualRuleJsonConverter))]
public class LessThanEqualRule : Rule
{
internal Rule A { get; }
internal Rule B { get; }
internal Rule? C { get; }
/// <summary>
/// The Lower bound.
/// </summary>
protected internal Rule A { get; }
/// <summary>
/// The middle argument.
/// </summary>
protected internal Rule B { get; }
/// <summary>
/// The Higher bound.
/// </summary>
protected internal Rule? C { get; }

internal LessThanEqualRule(Rule a, Rule b)
/// <summary>
/// Creates a new instance of <see cref="LessThanEqualRule"/> when '<=' operator is detected within json logic.
/// </summary>
/// <param name="a">The value to test.</param>
/// <param name="b">The boundary to test against.</param>
protected internal LessThanEqualRule(Rule a, Rule b)
{
A = a;
B = b;
}
internal LessThanEqualRule(Rule a, Rule b, Rule c)
/// <summary>
/// Creates a new instance of <see cref="LessThanEqualRule"/> when '<=' operator is detected within json logic.
/// </summary>
/// <param name="a">The lower bound.</param>
/// <param name="b">The middle argument.</param>
/// <param name="c">The upper bound.</param>
protected internal LessThanEqualRule(Rule a, Rule b, Rule c)
{
A = a;
B = b;
Expand Down
30 changes: 25 additions & 5 deletions JsonLogic/Rules/LessThanRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,37 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(LessThanRuleJsonConverter))]
public class LessThanRule : Rule
{
internal Rule A { get; }
internal Rule B { get; }
internal Rule? C { get; }
/// <summary>
/// The Lower bound.
/// </summary>
protected internal Rule A { get; }
/// <summary>
/// The middle argument.
/// </summary>
protected internal Rule B { get; }
/// <summary>
/// The Higher bound.
/// </summary>
protected internal Rule? C { get; }

internal LessThanRule(Rule a, Rule b)
/// <summary>
/// Creates a new instance of <see cref="LessThanRule"/> when '<' operator is detected within json logic.
/// </summary>
/// <param name="a">The argument to test.</param>
/// <param name="b">The boundary to test against.</param>
protected internal LessThanRule(Rule a, Rule b)
{
A = a;
B = b;
}

internal LessThanRule(Rule a, Rule b, Rule c)
/// <summary>
/// Creates a new instance of <see cref="LessThanRule"/> when '<' operator is detected within json logic.
/// </summary>
/// <param name="a">The lower bound.</param>
/// <param name="b">The middle argument.</param>
/// <param name="c">The upper bound.</param>
protected internal LessThanRule(Rule a, Rule b, Rule c)
{
A = a;
B = b;
Expand Down
17 changes: 14 additions & 3 deletions JsonLogic/Rules/LooseEqualsRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(LooseEqualsRuleJsonConverter))]
public class LooseEqualsRule : Rule
{
internal Rule A { get; }
internal Rule B { get; }
/// <summary>
/// First value to compare.
/// </summary>
protected internal Rule A { get; }
/// <summary>
/// Second value to compare.
/// </summary>
protected internal Rule B { get; }

internal LooseEqualsRule(Rule a, Rule b)
/// <summary>
/// Creates a new instance of <see cref="LooseEqualsRule"/> when '==' operator is detected within json logic.
/// </summary>
/// <param name="a">First value to compare.</param>
/// <param name="b">Second value to compare.</param>
protected internal LooseEqualsRule(Rule a, Rule b)
{
A = a;
B = b;
Expand Down

0 comments on commit 235fa3f

Please sign in to comment.