fetlife / rollout

Feature flippers.
MIT License
2.89k stars 212 forks source link

Add support to evaluate against arbitrary objects #124

Closed thejchap closed 5 years ago

thejchap commented 7 years ago

Hi, This PR adds support to evaluate whether a feature is active or not based on an arbitrary object/condition. Use case would be enabling a feature only on certain products, clients (multi tenant sites) or things like that.

For example

rollout.define_context :v2_page_products do |product|
  product.created_at > some_date
end
<%- if rollout.active?(:product_page_v2, @product, :v2_page_products) %>
  <%= render 'product_page_v2' %>
<% else %>
  <%= render 'product_page_v1' %>
<% end %>

Open to other ways of implementing this if its a feature that would be useful to other people

thejchap commented 7 years ago

Will clean this up/get CI passing if/when we decide to add this feature

reneklacan commented 7 years ago

@thejchap Thank for taking the time to submit a PR but have you seen Rollout groups? (https://github.com/fetlife/rollout#groups)

If yes, how is the goal of this feature different from it?

thejchap commented 7 years ago

@reneklacan unless I'm missing something, the gem currently assumes you only ever pass one type of model or object into active?....the gem stores/looks up the user's ID to determine if a feature should be active for a user. So, there could potentially be collision issues if more than one type of object are passed in (ie the ID property isnt globally unique across all tables or whatever)

I guess the alternative without any code changes would be passing in id_user_by with some other sort of ID that uses the class or table name or something (like users:1), but then its just a bit messy that it's referred to as a user all throughout the gem even if it could be something else

Definitely open to other ideas/suggestions that would achieve the same goal