Module: LaunchDarkly::Impl::Model

Defined in:
lib/ldclient-rb/impl/model/clause.rb,
lib/ldclient-rb/impl/model/segment.rb,
lib/ldclient-rb/impl/model/feature_flag.rb,
lib/ldclient-rb/impl/model/serialization.rb,
lib/ldclient-rb/impl/model/preprocessed_data.rb

Overview

Since:

  • 5.5.0

Defined Under Namespace

Classes: Clause, EvalResultFactoryMultiVariations, EvalResultsForSingleVariation, FeatureFlag, FlagRule, MigrationSettings, Preprocessor, Prerequisite, Rollout, Segment, SegmentRule, SegmentTarget, Target, VariationOrRollout, WeightedVariation

Class Method Summary collapse

Class Method Details

.deserialize(kind, input, logger = nil) ⇒ Object

Abstraction of deserializing a feature flag or segment that was read from a data store or received from LaunchDarkly.

SDK code outside of Impl::Model should use this method instead of calling the model class constructors directly, so as not to rely on implementation details.

Parameters:

  • kind (Hash)

    normally either FEATURES or SEGMENTS

  • input (object)

    a JSON string or a parsed hash (or a data model object, in which case we’ll just return the original object)

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

    logs errors if there are any data validation problems

Returns:

  • (Object)

    the flag or segment (or, for an unknown data kind, the data as a hash)

Since:

  • 5.5.0



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ldclient-rb/impl/model/serialization.rb', line 42

def self.deserialize(kind, input, logger = nil)
  return nil if input.nil?
  return input if !input.is_a?(String) && !input.is_a?(Hash)
  data = input.is_a?(Hash) ? input : JSON.parse(input, symbolize_names: true)
  case kind
  when FEATURES
    FeatureFlag.new(data, logger)
  when SEGMENTS
    Segment.new(data, logger)
  else
    data
  end
end

.make_all_store_data(received_data, logger = nil) ⇒ Object

Translates a { flags: …, segments: … } object received from LaunchDarkly to the data store format.

Since:

  • 5.5.0



64
65
66
67
68
69
# File 'lib/ldclient-rb/impl/model/serialization.rb', line 64

def self.make_all_store_data(received_data, logger = nil)
  {
    FEATURES => (received_data[:flags] || {}).transform_values { |data| FeatureFlag.new(data, logger) },
    SEGMENTS => (received_data[:segments] || {}).transform_values { |data| Segment.new(data, logger) },
  }
end

.serialize(kind, item) ⇒ Object

Abstraction of serializing a feature flag or segment that will be written to a data store. Currently we just call to_json, but SDK code outside of Impl::Model should use this method instead of to_json, so as not to rely on implementation details.

Since:

  • 5.5.0



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

def self.serialize(kind, item)
  item.to_json
end