Skip to content

Instantly share code, notes, and snippets.

@n8
Last active January 23, 2020 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8/509f000552291c1943fe5d87018bae81 to your computer and use it in GitHub Desktop.
Save n8/509f000552291c1943fe5d87018bae81 to your computer and use it in GitHub Desktop.
require 'zlib'
module FeatureFlags
BETA_ACCOUNTS = %w(subdomain1 subdomain2)
FLAGS = {
:new_import_flow => {
:percentage => 10,
:account_subdomains => []
},
:last_emailed_with => {
:percentage => 25,
:account_subdomains => [
'coolcustomer',
'anothercoolcustomer'
]
}
}
def self.enabled_for_account?(account, feature)
if config = FLAGS[feature]
return true if BETA_ACCOUNTS.include?(account.subdomain)
return true if config[:account_subdomains] && config[:account_subdomains].include?(account.subdomain)
return true if Zlib.crc32("#{feature}:#{account.id}") % 100 < config[:percentage]
end
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment