Class: Growthbook::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/growthbook/feature.rb

Overview

The feature with a generic value type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature) ⇒ Feature

Returns a new instance of Feature.



12
13
14
15
16
17
18
19
20
21
# File 'lib/growthbook/feature.rb', line 12

def initialize(feature)
  @default_value = get_option(feature, :defaultValue)

  rules = get_option(feature, :rules)

  @rules = []
  rules&.each do |rule|
    @rules << Growthbook::FeatureRule.new(rule)
  end
end

Instance Attribute Details

#default_valueAny? (readonly)

Returns:

  • (Any, nil)


7
8
9
# File 'lib/growthbook/feature.rb', line 7

def default_value
  @default_value
end

#rulesArray<Growthbook::FeatureRule> (readonly)

Returns:



10
11
12
# File 'lib/growthbook/feature.rb', line 10

def rules
  @rules
end

Instance Method Details

#to_json(*_args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/growthbook/feature.rb', line 23

def to_json(*_args)
  res = {}
  res['defaultValue'] = @default_value unless @default_value.nil?
  res['rules'] = []
  @rules.each do |rule|
    res['rules'] << rule.to_json
  end
  res
end