Class: LaunchDarkly::Impl::Model::FeatureFlag

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/model/feature_flag.rb

Overview

Since:

  • 5.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, logger = nil) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.

Parameters:

  • data (Hash)
  • logger (Logger|nil) (defaults to: nil)

Raises:

  • (ArgumentError)

Since:

  • 5.5.0



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 21

def initialize(data, logger = nil)
  raise ArgumentError, "expected hash but got #{data.class}" unless data.is_a?(Hash)
  errors = []
  @data = data
  @key = data[:key]
  @version = data[:version]
  @deleted = !!data[:deleted]
  return if @deleted
  @variations = data[:variations] || []
  @on = !!data[:on]
  fallthrough = data[:fallthrough] || {}
  @fallthrough = VariationOrRollout.new(fallthrough[:variation], fallthrough[:rollout], self, errors, "fallthrough")
  @off_variation = data[:offVariation]
  check_variation_range(self, errors, @off_variation, "off variation")
  @prerequisites = (data[:prerequisites] || []).map do |prereq_data|
    Prerequisite.new(prereq_data, self, errors)
  end
  @targets = (data[:targets] || []).map do |target_data|
    Target.new(target_data, self, errors)
  end
  @context_targets = (data[:contextTargets] || []).map do |target_data|
    Target.new(target_data, self, errors)
  end
  @rules = (data[:rules] || []).map.with_index do |rule_data, index|
    FlagRule.new(rule_data, index, self, errors)
  end
  @salt = data[:salt]
  @off_result = EvaluatorHelpers.evaluation_detail_for_off_variation(self, EvaluationReason::off)
  @fallthrough_results = Preprocessor.precompute_multi_variation_results(self,
      EvaluationReason::fallthrough(false), EvaluationReason::fallthrough(true))
  unless logger.nil?
    errors.each do |message|
      logger.error("[LDClient] Data inconsistency in feature flag \"#{@key}\": #{message}")
    end
  end
end

Instance Attribute Details

#context_targetsArray<LaunchDarkly::Impl::Model::Target> (readonly)

Returns:

Since:

  • 5.5.0



83
84
85
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 83

def context_targets
  @context_targets
end

#dataHash (readonly)

Returns:

  • (Hash)

Since:

  • 5.5.0



59
60
61
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 59

def data
  @data
end

#deletedBoolean (readonly)

Returns:

  • (Boolean)

Since:

  • 5.5.0



65
66
67
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 65

def deleted
  @deleted
end

#fallthroughLaunchDarkly::Impl::Model::VariationOrRollout (readonly)



73
74
75
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 73

def fallthrough
  @fallthrough
end

#fallthrough_resultsLaunchDarkly::Impl::Model::EvalResultFactoryMultiVariations (readonly)



77
78
79
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 77

def fallthrough_results
  @fallthrough_results
end

#keyString (readonly)

Returns:

  • (String)

Since:

  • 5.5.0



61
62
63
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 61

def key
  @key
end

#off_resultLaunchDarkly::EvaluationDetail (readonly)

Returns:

Since:

  • 5.5.0



75
76
77
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 75

def off_result
  @off_result
end

#off_variationInteger|nil (readonly)

Returns:

  • (Integer|nil)

Since:

  • 5.5.0



71
72
73
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 71

def off_variation
  @off_variation
end

#onBoolean (readonly)

Returns:

  • (Boolean)

Since:

  • 5.5.0



69
70
71
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 69

def on
  @on
end

#prerequisitesArray<LaunchDarkly::Impl::Model::Prerequisite> (readonly)

Returns:

Since:

  • 5.5.0



79
80
81
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 79

def prerequisites
  @prerequisites
end

#rulesArray<LaunchDarkly::Impl::Model::FlagRule> (readonly)

Returns:

Since:

  • 5.5.0



85
86
87
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 85

def rules
  @rules
end

#saltString (readonly)

Returns:

  • (String)

Since:

  • 5.5.0



87
88
89
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 87

def salt
  @salt
end

#targetsArray<LaunchDarkly::Impl::Model::Target> (readonly)

Returns:

Since:

  • 5.5.0



81
82
83
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 81

def targets
  @targets
end

#variationsArray (readonly)

Returns:

  • (Array)

Since:

  • 5.5.0



67
68
69
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 67

def variations
  @variations
end

#versionInteger (readonly)

Returns:

  • (Integer)

Since:

  • 5.5.0



63
64
65
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 63

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object

Since:

  • 5.5.0



96
97
98
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 96

def ==(other)
  other.is_a?(FeatureFlag) && other.data == self.data
end

#[](key) ⇒ Object

This method allows us to read properties of the object as if it’s just a hash. Currently this is necessary because some data store logic is still written to expect hashes; we can remove it once we migrate entirely to using attributes of the class.

Since:

  • 5.5.0



92
93
94
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 92

def [](key)
  @data[key]
end

#as_jsonObject

parameter is unused, but may be passed if we’re using the json gem

Since:

  • 5.5.0



100
101
102
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 100

def as_json(*) # parameter is unused, but may be passed if we're using the json gem
  @data
end

#to_json(*a) ⇒ Object

Same as as_json, but converts the JSON structure into a string.

Since:

  • 5.5.0



105
106
107
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 105

def to_json(*a)
  as_json.to_json(*a)
end