diff --git a/lib/flipper/expression/builder.rb b/lib/flipper/expression/builder.rb index 8dc45605f..6425389b1 100644 --- a/lib/flipper/expression/builder.rb +++ b/lib/flipper/expression/builder.rb @@ -53,6 +53,10 @@ def less_than_or_equal_to(object) alias lte less_than_or_equal_to alias less_than_or_equal less_than_or_equal_to + def include(object) + build({ Include: [self, object] }) + end + def percentage_of_actors(object) build({ PercentageOfActors: [self, build(object)] }) end diff --git a/lib/flipper/expressions/include.rb b/lib/flipper/expressions/include.rb new file mode 100644 index 000000000..38b59a95c --- /dev/null +++ b/lib/flipper/expressions/include.rb @@ -0,0 +1,9 @@ +module Flipper + module Expressions + class Include < Comparable + def self.operator + :include? + end + end + end +end diff --git a/spec/flipper/expression_spec.rb b/spec/flipper/expression_spec.rb index 54f9f72ee..bec0cfadf 100644 --- a/spec/flipper/expression_spec.rb +++ b/spec/flipper/expression_spec.rb @@ -79,6 +79,19 @@ ]) end + it "can build Include" do + expression = described_class.build({ + "Inlcude" => [["hello"], "hello"] + }) + + expect(expression).to be_instance_of(Flipper::Expression) + expect(expression.function).to be(Flipper::Expressions::Include) + expect(expression.args).to eq([ + Flipper.constant(["hello"]), + Flipper.constant("hello"), + ]) + end + it "can build NotEqual" do expression = described_class.build({ "NotEqual" => [