Class: Bugsnag::FeatureFlag

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag/feature_flag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, variant = nil) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.

Parameters:

  • name (String)

    The name of this feature flags

  • variant (String, nil) (defaults to: nil)

    An optional variant for this flag



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

#nameString (readonly)

Get the name of this feature flag

Returns:

  • (String)


6
7
8
# File 'lib/bugsnag/feature_flag.rb', line 6

def name
  @name
end

#variantString? (readonly)

Get the variant of this feature flag

Returns:

  • (String, nil)


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

#hashObject



24
25
26
# File 'lib/bugsnag/feature_flag.rb', line 24

def hash
  [@name, @variant].hash
end

#to_hHash{String => String}

Convert this flag to a hash

Examples:

With no variant

{ "featureFlag" => "name" }

With a variant

{ "featureFlag" => "name", "variant" => "variant" }

Returns:

  • (Hash{String => String})


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

Returns:

  • (Boolean)


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