28
loading...
This website collects cookies to deliver better user experience
class FeatureFlag
def self.enabled?(feature_name)
case feature_name
when 'awesome-feature'
true
else
true
end
end
end
class FeatureFlag
def self.enabled?(feature_name)
if @features.key?(feature_name.to_s)
@features[feature_name.to_s]
else
false
end
end
def self.load
@setting = YAML.safe_load(File.read(config.setting_path))
@features = @setting['features']
raise "The number of flags is limited to #{config.feature_limit}" if @features.count > config.feature_limit
end
def self.config
@config ||= Config.new
end
def self.configure
yield config
end
class Config
include ActiveSupport::Configurable
config_accessor :setting_path do
''
end
config_accessor :feature_limit do
0
end
end
end
FeatureFlag.configure do |config|
config.setting_path = Rails.root.join('config', 'feature_flag.yml')
config.feature_limit = 5
end
FeatureFlag.load
features:
awesome-feature: true