Sha256: 4694047d09dc8c0cdb5414a4848e7ee068c15d39114bdb1b601e3c8a485062b6
Contents?: true
Size: 1.3 KB
Versions: 18
Compression:
Stored size: 1.3 KB
Contents
module Prefab class FeatureFlagClient MAX_32_FLOAT = 4294967294.0 def initialize(base_client) @base_client = base_client end def upsert(feature_name, feature_obj) @base_client.config_client.upsert(feature_name, Prefab::ConfigValue.new(feature_flag: feature_obj)) end def feature_is_on?(feature_name) feature_is_on_for?(feature_name, nil) end def feature_is_on_for?(feature_name, lookup_key, attributes: []) @base_client.stats.increment("prefab.featureflag.on", tags: ["feature:#{feature_name}"]) feature_obj = @base_client.config_client.get(feature_name) return is_on?(feature_name, lookup_key, attributes, feature_obj) end private def is_on?(feature_name, lookup_key, attributes, feature_obj) if feature_obj.nil? return false end attributes << lookup_key if lookup_key if (attributes & feature_obj.whitelisted).size > 0 return true end if lookup_key return get_user_pct(feature_name, lookup_key) < feature_obj.pct end return feature_obj.pct > rand() end def get_user_pct(feature, lookup_key) to_hash = "#{@base_client.account_id}#{feature}#{lookup_key}" int_value = Murmur3.murmur3_32(to_hash) int_value / MAX_32_FLOAT end end end
Version data entries
18 entries across 18 versions & 1 rubygems