Class: LaunchDarkly::Impl::Model::Segment Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, logger = nil) ⇒ Segment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Segment.

Parameters:

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

Raises:

  • (ArgumentError)

Since:

  • 5.5.0



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
42
# File 'lib/ldclient-rb/impl/model/segment.rb', line 13

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]
  @override = false
  return if @deleted
  @included = data[:included] || []
  @excluded = data[:excluded] || []
  @included_contexts = (data[:includedContexts] || []).map do |target_data|
    SegmentTarget.new(target_data)
  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, 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

Instance Attribute Details

#data ⇒ Hash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)

Since:

  • 5.5.0



45
46
47
# File 'lib/ldclient-rb/impl/model/segment.rb', line 45

def data
  @data
end

#deleted ⇒ Boolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 5.5.0



51
52
53
# File 'lib/ldclient-rb/impl/model/segment.rb', line 51

def deleted
  @deleted
end

#excluded ⇒ Array<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)

Since:

  • 5.5.0



55
56
57
# File 'lib/ldclient-rb/impl/model/segment.rb', line 55

def excluded
  @excluded
end

#excluded_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 5.5.0



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

def excluded_contexts
  @excluded_contexts
end

#generation ⇒ Integer|nil (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer|nil)

Since:

  • 5.5.0



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

def generation
  @generation
end

#included ⇒ Array<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)

Since:

  • 5.5.0



53
54
55
# File 'lib/ldclient-rb/impl/model/segment.rb', line 53

def included
  @included
end

#included_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 5.5.0



57
58
59
# File 'lib/ldclient-rb/impl/model/segment.rb', line 57

def included_contexts
  @included_contexts
end

#key ⇒ String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

Since:

  • 5.5.0



47
48
49
# File 'lib/ldclient-rb/impl/model/segment.rb', line 47

def key
  @key
end

#rules ⇒ Array<SegmentRule> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 5.5.0



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

def rules
  @rules
end

#salt ⇒ String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

Since:

  • 5.5.0



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

def salt
  @salt
end

#unbounded ⇒ Boolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 5.5.0



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

def unbounded
  @unbounded
end

#unbounded_context_kind ⇒ String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

Since:

  • 5.5.0



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

def unbounded_context_kind
  @unbounded_context_kind
end

#version ⇒ Integer (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)

Since:

  • 5.5.0



49
50
51
# File 'lib/ldclient-rb/impl/model/segment.rb', line 49

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0



107
108
109
# File 'lib/ldclient-rb/impl/model/segment.rb', line 107

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

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



103
104
105
# File 'lib/ldclient-rb/impl/model/segment.rb', line 103

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

#as_json ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Since:

  • 5.5.0



111
112
113
# File 'lib/ldclient-rb/impl/model/segment.rb', line 111

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

#as_override ⇒ Segment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a shallow copy of this segment that carries the override marker. The copy shares its data with this segment. Nothing writes to that data. This segment is not changed.

Flag overrides are currently experimental and subject to change.

Returns:

Since:

  • 5.5.0



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

def as_override
  copy = dup
  copy.override = true
  copy
end

#override? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

True if this definition came from the SDK's override store rather than from LaunchDarkly data. The marker is not part of the segment data and is never serialized. Only the SDK components that manage override entries set it, through #as_override. Evaluation reads it to mark the evaluations it affects. Every other reader treats a marked definition the same as any other.

Flag overrides are currently experimental and subject to change.

Returns:

  • (Boolean)

Since:

  • 5.5.0



82
83
84
# File 'lib/ldclient-rb/impl/model/segment.rb', line 82

def override?
  @override
end

#to_json(*a) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Since:

  • 5.5.0



116
117
118
# File 'lib/ldclient-rb/impl/model/segment.rb', line 116

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