Class: LaunchDarkly::Impl::Model::FeatureFlag
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Model::FeatureFlag
- Defined in:
- lib/ldclient-rb/impl/model/feature_flag.rb
Overview
Instance Attribute Summary collapse
- #context_targets ⇒ Array<LaunchDarkly::Impl::Model::Target> readonly
- #data ⇒ Hash readonly
- #deleted ⇒ Boolean readonly
- #fallthrough ⇒ LaunchDarkly::Impl::Model::VariationOrRollout readonly
- #fallthrough_results ⇒ LaunchDarkly::Impl::Model::EvalResultFactoryMultiVariations readonly
- #key ⇒ String readonly
- #off_result ⇒ LaunchDarkly::EvaluationDetail readonly
- #off_variation ⇒ Integer|nil readonly
- #on ⇒ Boolean readonly
- #prerequisites ⇒ Array<LaunchDarkly::Impl::Model::Prerequisite> readonly
- #rules ⇒ Array<LaunchDarkly::Impl::Model::FlagRule> readonly
- #salt ⇒ String readonly
- #targets ⇒ Array<LaunchDarkly::Impl::Model::Target> readonly
- #variations ⇒ Array readonly
- #version ⇒ Integer readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](key) ⇒ Object
This method allows us to read properties of the object as if it’s just a hash.
-
#as_json ⇒ Object
parameter is unused, but may be passed if we’re using the json gem.
-
#initialize(data, logger = nil) ⇒ FeatureFlag
constructor
A new instance of FeatureFlag.
-
#to_json(*a) ⇒ Object
Same as as_json, but converts the JSON structure into a string.
Constructor Details
#initialize(data, logger = nil) ⇒ FeatureFlag
Returns a new instance of FeatureFlag.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 13 def initialize(data, logger = nil) raise ArgumentError, "expected hash but got #{data.class}" unless data.is_a?(Hash) @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]) @off_variation = data[:offVariation] @prerequisites = (data[:prerequisites] || []).map do |prereq_data| Prerequisite.new(prereq_data, self, logger) end @targets = (data[:targets] || []).map do |target_data| Target.new(target_data, self, logger) end @context_targets = (data[:contextTargets] || []).map do |target_data| Target.new(target_data, self, logger) end @rules = (data[:rules] || []).map.with_index do |rule_data, index| FlagRule.new(rule_data, index, self, logger) end @salt = data[:salt] @off_result = EvaluatorHelpers.evaluation_detail_for_off_variation(self, EvaluationReason::off, logger) @fallthrough_results = Preprocessor.precompute_multi_variation_results(self, EvaluationReason::fallthrough(false), EvaluationReason::fallthrough(true)) end |
Instance Attribute Details
#context_targets ⇒ Array<LaunchDarkly::Impl::Model::Target> (readonly)
68 69 70 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 68 def context_targets @context_targets end |
#data ⇒ Hash (readonly)
44 45 46 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 44 def data @data end |
#deleted ⇒ Boolean (readonly)
50 51 52 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 50 def deleted @deleted end |
#fallthrough ⇒ LaunchDarkly::Impl::Model::VariationOrRollout (readonly)
58 59 60 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 58 def fallthrough @fallthrough end |
#fallthrough_results ⇒ LaunchDarkly::Impl::Model::EvalResultFactoryMultiVariations (readonly)
62 63 64 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 62 def fallthrough_results @fallthrough_results end |
#key ⇒ String (readonly)
46 47 48 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 46 def key @key end |
#off_result ⇒ LaunchDarkly::EvaluationDetail (readonly)
60 61 62 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 60 def off_result @off_result end |
#off_variation ⇒ Integer|nil (readonly)
56 57 58 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 56 def off_variation @off_variation end |
#on ⇒ Boolean (readonly)
54 55 56 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 54 def on @on end |
#prerequisites ⇒ Array<LaunchDarkly::Impl::Model::Prerequisite> (readonly)
64 65 66 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 64 def prerequisites @prerequisites end |
#rules ⇒ Array<LaunchDarkly::Impl::Model::FlagRule> (readonly)
70 71 72 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 70 def rules @rules end |
#salt ⇒ String (readonly)
72 73 74 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 72 def salt @salt end |
#targets ⇒ Array<LaunchDarkly::Impl::Model::Target> (readonly)
66 67 68 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 66 def targets @targets end |
#variations ⇒ Array (readonly)
52 53 54 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 52 def variations @variations end |
#version ⇒ Integer (readonly)
48 49 50 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 48 def version @version end |
Instance Method Details
#==(other) ⇒ Object
81 82 83 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 81 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.
77 78 79 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 77 def [](key) @data[key] end |
#as_json ⇒ Object
parameter is unused, but may be passed if we’re using the json gem
85 86 87 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 85 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.
90 91 92 |
# File 'lib/ldclient-rb/impl/model/feature_flag.rb', line 90 def to_json(*a) as_json.to_json(a) end |