-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Expressions #692
Expressions #692
Conversation
:party:
I don't think this is done but they are green for now .
Co-authored-by: John Nunemaker <nunemaker@gmail.com>
Add Time, Now, and Duration expression types
* origin/main: Fix typo in comment Update Changelog.md
…s-experiment * origin/learn-the-rules:
Refactor expressions
So excited for this! Game changer 🎉 |
When an expression match requires a method call (such as "user.admin?") should we expect to just add additional values to "flipper_properties"? def flipper_properties
super.merge!("is_admin" => admin?)
end |
@swishstache Yep, that's what we were thinking. Does that work for you? |
It does! 🎉👍 |
When using multiple actors, how might we achieve a match for a combination of them? For example, enabling a feature for "basic plan" user actors but, only for those that belong to a specific organization actor. Example Code (based on the code from "examples/expressions.rb") org_foo = Org.new(1, {
"type" => "Org",
"id" => 1,
"now" => NOW,
})
org_bar = Org.new(33, {
"type" => "Org",
"id" => 33,
"now" => NOW,
})
user_ted = User.new(1, {
"type" => "User",
"id" => 1,
"plan" => "basic",
"age" => 39,
"team_user" => true,
"now" => NOW,
})
user_lasso = User.new(32, {
"type" => "User",
"id" => 32,
"plan" => "basic",
"age" => 39,
"team_user" => true,
"now" => NOW,
})
# Basic plan users under Foo org only
is_foo_org = Flipper.property(:type).eq("Org"), Flipper.property(:flipper_id).eq("Org;1")
is_basic_plan_user = Flipper.property(:type).eq("User"), Flipper.property(:plan).eq("basic")
Flipper.enable :neat_feature, Flipper.all(is_foo_org, is_basic_plan_user)
# A basic plan user under Foo organization
assert Flipper.enabled?(:neat_feature, [org_foo, user_ted]) # => Expected true but was false. Please correct.
# A basic plan user under Bar organization
refute Flipper.enabled?(:neat_feature, [org_bar, user_lasso]) # => false |
@swishstache I'd collapse the actors into the properties. For expressions, the goal would be to pass all the context in one actor and then let the expression sort it out. For example, instead of passing org and user, I'd pass the user with the current org in the properties. Forgive any typos or slight incorrectness in the pseudo-code below... class OrgUser
include Flipper::Actor
def initialize(org, user)
@user = user
@org = org
end
def flipper_id
"User;#{@user.id};Org;#{@org.id}" # or it could be @user.flipper_id or whatever makes sense
end
def flipper_properties
@user.flipper_properties.merge("org_id" => @org.id)
end
end
org_foo = Org.new(1, {
"type" => "Org",
"id" => 1,
"now" => NOW,
})
org_bar = Org.new(33, {
"type" => "Org",
"id" => 33,
"now" => NOW,
})
user_ted = User.new(1, {
"type" => "User",
"id" => 1,
"plan" => "basic",
"age" => 39,
"team_user" => true,
"now" => NOW,
"org_id" => 1,
})
user_lasso = User.new(32, {
"type" => "User",
"id" => 32,
"plan" => "basic",
"age" => 39,
"team_user" => true,
"now" => NOW,
"org_id" => 33,
})
# Basic plan users under Foo org only
is_foo_org = Flipper.property(:org_id).eq(1)
is_basic_plan_user = Flipper.all(Flipper.property(:type).eq("User"), Flipper.property(:plan).eq("basic"))
Flipper.enable :neat_feature, Flipper.all(is_foo_org, is_basic_plan_user)
# A basic plan user under Foo organization
assert Flipper.enabled?(:neat_feature, OrgUser.new(org_foo, user_ted)) # => true
# A basic plan user under Bar organization
refute Flipper.enabled?(:neat_feature, OrgUser.new(org_bar, user_lasso)) # => false @bkeepers has been knee deep in this so he may have better ideas, but I was picturing something like that. The only other thing I can think of is to merge all properties into one big hash but then you have to deal with collisions of property keys which seems painful. |
* origin/main: Update changelog Improve performance of `color_name` function in log subscriber Update Changelog.md remove remote source from CSP. Bundle bootstrap, jquery and poppler. Add mirroring example Use new method of making logs bold Add a key_prefix option to the Redis adapter
* main: Prepare for 0.28.1
2ea6f6d
to
189df7f
Compare
I'm going to work on getting this released this week as "alpha", so I'm going to go ahead and merge this and I'll track any further work in #557. |
…d `percentage_of_time` methods on `Flipper` and `Flipper::DSL` Backported from #692
…d `percentage_of_time` methods on `Flipper` and `Flipper::DSL` Backported from #692
Described by @jnunemaker in #557, Expressions are a new syntax for defining rules in Flipper and will enable much more sophisticated feature flipping. We're going to try to get this merged into Flipper as an experimental new feature while we put the finishing touches on it.