Skip to content

Commit ee46fab

Browse files
committed
Add Min/Max functions
1 parent 0d065b5 commit ee46fab

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

lib/flipper/expressions/max.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "flipper/expression"
2+
3+
module Flipper
4+
module Expressions
5+
class Max
6+
def self.call(*args)
7+
args.max
8+
end
9+
end
10+
end
11+
end

lib/flipper/expressions/min.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "flipper/expression"
2+
3+
module Flipper
4+
module Expressions
5+
class Min
6+
def self.call(*args)
7+
args.min
8+
end
9+
end
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Max.schema.json",
4+
"title": "Max",
5+
"$ref": "schema.json#/$defs/arguments(n)"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Min.schema.json",
4+
"title": "Min",
5+
"$ref": "schema.json#/$defs/arguments(n)"
6+
}

packages/expressions/schemas/schema.json

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"GreaterThanOrEqualTo": { "$ref": "GreaterThanOrEqualTo.schema.json" },
3030
"LessThan": { "$ref": "LessThan.schema.json" },
3131
"LessThanOrEqualTo": { "$ref": "LessThanOrEqualTo.schema.json" },
32+
"Max": { "$ref": "Max.schema.json" },
33+
"Min": { "$ref": "Min.schema.json" },
3234
"NotEqual": { "$ref": "NotEqual.schema.json" },
3335
"Now": { "$ref": "Now.schema.json" },
3436
"Number": { "$ref": "Number.schema.json" },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Max": [] },
5+
"result": { "enum": [null] }
6+
},
7+
{
8+
"expression": { "Max": [3, 2, 1] },
9+
"result": { "enum": [3] }
10+
},
11+
{
12+
"expression": { "Max": [0.1, 0.2] },
13+
"result": { "enum": [0.2] }
14+
},
15+
{
16+
"expression": { "Max": ["a", "b"] },
17+
"result": { "enum": ["b"] }
18+
},
19+
{
20+
"expression": { "Max": 100 },
21+
"result": { "enum": [100] }
22+
},
23+
{
24+
"expression": { "Max": [{ "Number": "2" }, { "Number": "1" }] },
25+
"result": { "enum": [2] }
26+
}
27+
],
28+
"invalid": [
29+
{ "Max": null },
30+
{ "Max": [], "Any": [] }
31+
]
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Min": [] },
5+
"result": { "enum": [null] }
6+
},
7+
{
8+
"expression": { "Min": [3, 2, 1] },
9+
"result": { "enum": [1] }
10+
},
11+
{
12+
"expression": { "Min": [0.1, 0.2] },
13+
"result": { "enum": [0.1] }
14+
},
15+
{
16+
"expression": { "Min": ["a", "b"] },
17+
"result": { "enum": ["a"] }
18+
},
19+
{
20+
"expression": { "Min": 100 },
21+
"result": { "enum": [100] }
22+
},
23+
{
24+
"expression": { "Min": [{ "Number": "2" }, { "Number": "1" }] },
25+
"result": { "enum": [1] }
26+
}
27+
],
28+
"invalid": [
29+
{ "Min": null },
30+
{ "Min": [], "Any": [] }
31+
]
32+
}

0 commit comments

Comments
 (0)