Class: Bugsnag::FeatureFlag
- Inherits:
-
Object
- Object
- Bugsnag::FeatureFlag
- Defined in:
- lib/bugsnag/feature_flag.rb
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Get the name of this feature flag.
-
#variant ⇒ String?
readonly
Get the variant of this feature flag.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(name, variant = nil) ⇒ FeatureFlag
constructor
A new instance of FeatureFlag.
-
#to_h ⇒ Hash{String => String}
Convert this flag to a hash.
-
#valid? ⇒ Boolean
Check if this flag is valid, i.e.
Constructor Details
#initialize(name, variant = nil) ⇒ FeatureFlag
Returns a new instance of FeatureFlag.
15 16 17 18 |
# File 'lib/bugsnag/feature_flag.rb', line 15 def initialize(name, variant = nil) @name = name @variant = coerce_variant(variant) end |
Instance Attribute Details
#name ⇒ String (readonly)
Get the name of this feature flag
6 7 8 |
# File 'lib/bugsnag/feature_flag.rb', line 6 def name @name end |
#variant ⇒ String? (readonly)
Get the variant of this feature flag
11 12 13 |
# File 'lib/bugsnag/feature_flag.rb', line 11 def variant @variant end |
Instance Method Details
#==(other) ⇒ Object
20 21 22 |
# File 'lib/bugsnag/feature_flag.rb', line 20 def ==(other) self.class == other.class && @name == other.name && @variant == other.variant end |
#hash ⇒ Object
24 25 26 |
# File 'lib/bugsnag/feature_flag.rb', line 24 def hash [@name, @variant].hash end |
#to_h ⇒ Hash{String => String}
Convert this flag to a hash
37 38 39 40 41 42 43 |
# File 'lib/bugsnag/feature_flag.rb', line 37 def to_h if @variant.nil? { "featureFlag" => @name } else { "featureFlag" => @name, "variant" => @variant } end end |
#valid? ⇒ Boolean
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
49 50 51 52 53 |
# File 'lib/bugsnag/feature_flag.rb', line 49 def valid? @name.is_a?(String) && !@name.empty? && (@variant.nil? || @variant.is_a?(String)) end |