module BetaFeature::Flagger::BetaFeatureInstanceMethods
Public Instance Methods
all_betas()
click to toggle source
# File lib/beta_feature/flagger.rb, line 44 def all_betas @__all_betas__ ||= begin clean_betas(find_or_create_beta_feature_setting.betas + BetaFeature.released.keys).to_set end end
can_access_beta?(*betas)
click to toggle source
# File lib/beta_feature/flagger.rb, line 19 def can_access_beta?(*betas) betas = betas.map(&:to_s) validate_beta_name(*betas) betas.all? {|key| all_betas.include?(key) } end
enable_beta!(*betas)
click to toggle source
add feature flags.
# File lib/beta_feature/flagger.rb, line 26 def enable_beta!(*betas) betas = betas.map(&:to_s) validate_beta_name(*betas) betas = clean_betas(find_or_create_beta_feature_setting.betas + betas) beta_feature_setting.update(betas: betas) flush_beta_cache end
remove_beta!(*betas)
click to toggle source
remove feature flags
# File lib/beta_feature/flagger.rb, line 35 def remove_beta!(*betas) betas = betas.map(&:to_s) validate_beta_name(*betas) betas = clean_betas(find_or_create_beta_feature_setting.betas - betas) beta_feature_setting.update(betas: betas) flush_beta_cache end
Private Instance Methods
clean_betas(betas)
click to toggle source
# File lib/beta_feature/flagger.rb, line 69 def clean_betas(betas) betas.map(&:to_s).uniq.compact.select{ |beta| BetaFeature.all_betas.key?(beta) } end
find_or_create_beta_feature_setting()
click to toggle source
# File lib/beta_feature/flagger.rb, line 61 def find_or_create_beta_feature_setting beta_feature_setting || create_beta_feature_setting end
flush_beta_cache()
click to toggle source
# File lib/beta_feature/flagger.rb, line 65 def flush_beta_cache remove_instance_variable(:@__all_betas__) if defined? @__all_betas__ end
validate_beta_name(*betas)
click to toggle source
# File lib/beta_feature/flagger.rb, line 52 def validate_beta_name(*betas) betas.each do |beta| if !BetaFeature.all_betas.key?(beta) msg = "Please define #{beta} in config/beta_features.yml" raise BetaFeature::BetaNotDefined.new(msg) end end end