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

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

Overview

Since:

  • 5.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, logger = nil) ⇒ Segment

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
# 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)
  @data = data
  @key = data[:key]
  @version = data[:version]
  @deleted = !!data[:deleted]
  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, logger)
  end
  @unbounded = !!data[:unbounded]
  @unbounded_context_kind = data[:unboundedContextKind] || LDContext::KIND_DEFAULT
  @generation = data[:generation]
  @salt = data[:salt]
end

Instance Attribute Details

#dataHash (readonly)

Returns:

  • (Hash)

Since:

  • 5.5.0



38
39
40
# File 'lib/ldclient-rb/impl/model/segment.rb', line 38

def data
  @data
end

#deletedBoolean (readonly)

Returns:

  • (Boolean)

Since:

  • 5.5.0



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

def deleted
  @deleted
end

#excludedArray<String> (readonly)

Returns:

  • (Array<String>)

Since:

  • 5.5.0



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

def excluded
  @excluded
end

#excluded_contextsArray<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)

Returns:

Since:

  • 5.5.0



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

def excluded_contexts
  @excluded_contexts
end

#generationInteger|nil (readonly)

Returns:

  • (Integer|nil)

Since:

  • 5.5.0



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

def generation
  @generation
end

#includedArray<String> (readonly)

Returns:

  • (Array<String>)

Since:

  • 5.5.0



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

def included
  @included
end

#included_contextsArray<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)

Returns:

Since:

  • 5.5.0



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

def included_contexts
  @included_contexts
end

#keyString (readonly)

Returns:

  • (String)

Since:

  • 5.5.0



40
41
42
# File 'lib/ldclient-rb/impl/model/segment.rb', line 40

def key
  @key
end

#rulesArray<SegmentRule> (readonly)

Returns:

Since:

  • 5.5.0



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

def rules
  @rules
end

#saltString (readonly)

Returns:

  • (String)

Since:

  • 5.5.0



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

def salt
  @salt
end

#unboundedBoolean (readonly)

Returns:

  • (Boolean)

Since:

  • 5.5.0



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

def unbounded
  @unbounded
end

#unbounded_context_kindString (readonly)

Returns:

  • (String)

Since:

  • 5.5.0



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

def unbounded_context_kind
  @unbounded_context_kind
end

#versionInteger (readonly)

Returns:

  • (Integer)

Since:

  • 5.5.0



42
43
44
# File 'lib/ldclient-rb/impl/model/segment.rb', line 42

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object

Since:

  • 5.5.0



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

def ==(other)
  other.is_a?(Segment) && 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



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

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



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

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



80
81
82
# File 'lib/ldclient-rb/impl/model/segment.rb', line 80

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