class Bugsnag::Utility::FeatureFlagDelegate
@api private
Public Class Methods
new()
click to toggle source
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 4 def initialize # feature flags are stored internally in a hash of "name" => <FeatureFlag> # we don't use a Set because new feature flags should overwrite old ones # that share a name, but FeatureFlag equality also uses the variant @storage = {} end
Public Instance Methods
add(name, variant)
click to toggle source
Add a feature flag with the given name & variant
@param name [String] @param variant [String, nil] @return [void]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 23 def add(name, variant) flag = Bugsnag::FeatureFlag.new(name, variant) return unless flag.valid? @storage[flag.name] = flag end
as_json()
click to toggle source
Get the feature flags in their JSON representation
@example
[ { "featureFlag" => "name", "variant" => "variant" }, { "featureFlag" => "another name" }, ]
@return [Array<Hash{String => String}>]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 85 def as_json to_a.map(&:to_h) end
clear()
click to toggle source
Remove all the stored flags
@return [void]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 59 def clear @storage.clear end
initialize_dup(original)
click to toggle source
Calls superclass method
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 11 def initialize_dup(original) super # copy the internal storage when 'dup' is called @storage = @storage.dup end
merge(feature_flags)
click to toggle source
Merge the given array of FeatureFlag
instances into the stored feature flags
New flags will be appended to the array. Flags with the same name will be overwritten, but their position in the array will not change
@param feature_flags [Array<Bugsnag::FeatureFlag>] @return [void]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 39 def merge(feature_flags) feature_flags.each do |flag| next unless flag.is_a?(Bugsnag::FeatureFlag) next unless flag.valid? @storage[flag.name] = flag end end
remove(name)
click to toggle source
Remove the stored flag with the given name
@param name [String] @return [void]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 52 def remove(name) @storage.delete(name) end
to_a()
click to toggle source
Get an array of FeatureFlag
instances
@example
[ <#Bugsnag::FeatureFlag>, <#Bugsnag::FeatureFlag>, ]
@return [Array<Bugsnag::FeatureFlag>]
# File lib/bugsnag/utility/feature_flag_delegate.rb, line 72 def to_a @storage.values end