From f39b8469c482dd5ae5124d5081589f29ddcf3dd6 Mon Sep 17 00:00:00 2001 From: Paulo Ancheta Date: Tue, 18 Jun 2024 08:56:49 -0700 Subject: [PATCH] create an include expression --- lib/flipper/expression/builder.rb | 4 ++++ lib/flipper/expressions/include.rb | 9 +++++++++ spec/flipper/expression_spec.rb | 13 +++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 lib/flipper/expressions/include.rb 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" => [