Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make operators in the specification private protected to allow inheritance. #369

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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);
dcook-net marked this conversation as resolved.
Show resolved Hide resolved

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
17 changes: 14 additions & 3 deletions JsonLogic/Rules/InRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ 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 Source { 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="source">The string value to test against.</param>
protected internal InRule(Rule test, Rule source)
{
Test = test;
Source = source;
Expand Down
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
17 changes: 14 additions & 3 deletions JsonLogic/Rules/LooseNotEqualsRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(LooseNotEqualsRuleJsonConverter))]
public class LooseNotEqualsRule : 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 LooseNotEqualsRule(Rule a, Rule b)
/// <summary>
/// Creates a new instance of <see cref="LooseNotEqualsRule"/> 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 LooseNotEqualsRule(Rule a, Rule b)
{
A = a;
B = b;
Expand Down
17 changes: 14 additions & 3 deletions JsonLogic/Rules/MapRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(MapRuleJsonConverter))]
public class MapRule : Rule
{
internal Rule Input { get; }
internal Rule Rule { get; }
/// <summary>
/// A sequence of values to map over.
/// </summary>
protected internal Rule Input { get; }
/// <summary>
/// A rule to apply to each item in the sequence.
/// </summary>
protected internal Rule Rule { get; }

internal MapRule(Rule input, Rule rule)
/// <summary>
/// Creates a new instance of <see cref="MapRule"/> when 'map' operator is detected within json logic.
/// </summary>
/// <param name="input">A sequence of values to map over.</param>
/// <param name="rule">A rule to apply to each item in the sequence.</param>
protected internal MapRule(Rule input, Rule rule)
{
Input = input;
Rule = rule;
Expand Down
12 changes: 10 additions & 2 deletions JsonLogic/Rules/MaxRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ namespace Json.Logic.Rules;
[JsonConverter(typeof(MaxRuleJsonConverter))]
public class MaxRule : Rule
{
internal List<Rule> Items { get; }
/// <summary>
/// The sequence of numbers to query for max.
/// </summary>
protected internal List<Rule> Items { get; }

internal MaxRule(Rule a, params Rule[] more)
/// <summary>
/// Creates a new instance of <see cref="MaxRule"/> when 'max' operator is detected within json logic.
/// </summary>
/// <param name="a">The first numeric value in a sequence of numbers.</param>
/// <param name="more">A sequence of numbers.</param>
protected internal MaxRule(Rule a, params Rule[] more)
{
Items = new List<Rule> { a };
Items.AddRange(more);
Expand Down