Class: LaunchDarkly::Impl::Model::Segment
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Model::Segment
- Defined in:
- lib/ldclient-rb/impl/model/segment.rb
Overview
Instance Attribute Summary collapse
- #data ⇒ Hash readonly
- #deleted ⇒ Boolean readonly
- #excluded ⇒ Array<String> readonly
- #excluded_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> readonly
- #generation ⇒ Integer|nil readonly
- #included ⇒ Array<String> readonly
- #included_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> readonly
- #key ⇒ String readonly
- #rules ⇒ Array<SegmentRule> readonly
- #salt ⇒ String readonly
- #unbounded ⇒ Boolean readonly
- #unbounded_context_kind ⇒ String 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) ⇒ Segment
constructor
A new instance of Segment.
-
#to_json(*a) ⇒ Object
Same as as_json, but converts the JSON structure into a string.
Constructor Details
#initialize(data, logger = nil) ⇒ Segment
Returns a new instance of Segment.
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/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] 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 || logger.error("[LDClient] Data inconsistency in segment \"#{@key}\": #{}") end end end |
Instance Attribute Details
#data ⇒ Hash (readonly)
44 45 46 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 44 def data @data end |
#deleted ⇒ Boolean (readonly)
50 51 52 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 50 def deleted @deleted end |
#excluded ⇒ Array<String> (readonly)
54 55 56 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 54 def excluded @excluded end |
#excluded_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)
58 59 60 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 58 def excluded_contexts @excluded_contexts end |
#generation ⇒ Integer|nil (readonly)
66 67 68 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 66 def generation @generation end |
#included ⇒ Array<String> (readonly)
52 53 54 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 52 def included @included end |
#included_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)
56 57 58 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 56 def included_contexts @included_contexts end |
#key ⇒ String (readonly)
46 47 48 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 46 def key @key end |
#rules ⇒ Array<SegmentRule> (readonly)
60 61 62 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 60 def rules @rules end |
#salt ⇒ String (readonly)
68 69 70 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 68 def salt @salt end |
#unbounded ⇒ Boolean (readonly)
62 63 64 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 62 def unbounded @unbounded end |
#unbounded_context_kind ⇒ String (readonly)
64 65 66 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 64 def unbounded_context_kind @unbounded_context_kind end |
#version ⇒ Integer (readonly)
48 49 50 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 48 def version @version end |
Instance Method Details
#==(other) ⇒ Object
77 78 79 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 77 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.
73 74 75 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 73 def [](key) @data[key] end |
#as_json ⇒ Object
parameter is unused, but may be passed if we're using the json gem
81 82 83 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 81 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.
86 87 88 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 86 def to_json(*a) as_json.to_json(*a) end |