lib/ldclient-rb/impl/model/segment.rb in launchdarkly-server-sdk-7.0.0 vs lib/ldclient-rb/impl/model/segment.rb in launchdarkly-server-sdk-7.0.1

- old
+ new

@@ -10,10 +10,11 @@ class Segment # @param data [Hash] # @param logger [Logger|nil] 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 @@ -24,16 +25,21 @@ end @excluded_contexts = (data[:excludedContexts] || []).map do |target_data| SegmentTarget.new(target_data) end @rules = (data[:rules] || []).map do |rule_data| - SegmentRule.new(rule_data, logger) + SegmentRule.new(rule_data, errors) end @unbounded = !!data[:unbounded] @unbounded_context_kind = data[:unboundedContextKind] || LDContext::KIND_DEFAULT @generation = data[:generation] @salt = data[:salt] + unless logger.nil? + errors.each do |message| + logger.error("[LDClient] Data inconsistency in segment \"#{@key}\": #{message}") + end + end end # @return [Hash] attr_reader :data # @return [String] @@ -96,13 +102,13 @@ # @return [Set] attr_reader :values end class SegmentRule - def initialize(data, logger) + def initialize(data, errors_out = nil) @data = data @clauses = (data[:clauses] || []).map do |clause_data| - Clause.new(clause_data, logger) + Clause.new(clause_data, errors_out) end @weight = data[:weight] @bucket_by = data[:bucketBy] @rollout_context_kind = data[:rolloutContextKind] end