class Bugsnag::FeatureFlag
Attributes
name[R]
Get the name of this feature flag
@return [String]
variant[R]
Get the variant of this feature flag
@return [String, nil]
Public Class Methods
new(name, variant = nil)
click to toggle source
@param name [String] The name of this feature flags @param variant [String, nil] An optional variant for this flag
# File lib/bugsnag/feature_flag.rb, line 15 def initialize(name, variant = nil) @name = name @variant = coerce_variant(variant) end
Public Instance Methods
==(other)
click to toggle source
# File lib/bugsnag/feature_flag.rb, line 20 def ==(other) self.class == other.class && @name == other.name && @variant == other.variant end
hash()
click to toggle source
# File lib/bugsnag/feature_flag.rb, line 24 def hash [@name, @variant].hash end
to_h()
click to toggle source
Convert this flag to a hash
@example With no variant
{ "featureFlag" => "name" }
@example With a variant
{ "featureFlag" => "name", "variant" => "variant" }
@return [Hash{String => String}]
# File lib/bugsnag/feature_flag.rb, line 37 def to_h if @variant.nil? { "featureFlag" => @name } else { "featureFlag" => @name, "variant" => @variant } end end
valid?()
click to toggle source
Check if this flag is valid, i.e. has a name that’s a String and a variant that’s either nil or a String
@return [Boolean]
# File lib/bugsnag/feature_flag.rb, line 49 def valid? @name.is_a?(String) && !@name.empty? && (@variant.nil? || @variant.is_a?(String)) end
Private Instance Methods
coerce_variant(variant)
click to toggle source
Coerce this variant into a valid value (String or nil)
If the variant is not already a string or nil, we use to_s to coerce it. If to_s raises, the variant will be set to nil
@param variant [Object] @return [String, nil]
# File lib/bugsnag/feature_flag.rb, line 64 def coerce_variant(variant) if variant.nil? || variant.is_a?(String) variant else variant.to_s end rescue StandardError nil end