howaboutwe / experimental

MIT License
20 stars 2 forks source link

Adds magic predicate methods for feature flipping #32

Closed bryanwoods closed 10 years ago

bryanwoods commented 10 years ago

This is probably way too aggressive, but just opening a PR to discuss implementing something like this. Essentially, I've noticed we've started writing helper methods to determine a feature's visibility for a user that look like this:

def foo?
  current_user.in_bucket?(:foo, 1)
end

def bar?
  current_user.in_bucket?(:bar, 1)
end

So this change would allow you to call a predicate method matching the desired experiment, eg:

# Experimental::Experiment[:everything_free]
puts "Everything is free!!!!" if user.everything_free?

The most obvious downside is the hardcoded '1' for the 'on' bucket. This is because the "onnyness" and "offyness" is currently in human-readable text in the notes section of the YAML file. Codifying this in some way like

some experiment:
  on: 1

Would alleviate that, but not sure whether or not we see that direction as beneficial.

I could also implement this in a much less extreme way -- wanted to open a dialogue about whether or not this is even useful.

oggy commented 10 years ago

I'd be -1 on "polluting" the user method namespace with experiment names. I'd be less so for a single feature_enabled?(name) method.

I agree that hardcoding 1 is a bad idea. For a start if you have 3 buckets, often 1 and 2 will be "on." Config option would work better - on the fence about whether it really helps tho.

bryanwoods commented 10 years ago

I'll close for now and submit something for the config changes for a future discussion sometime