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 |
# 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
#data ⇒ Hash (readonly)
38 39 40 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 38 def data @data end |
#deleted ⇒ Boolean (readonly)
44 45 46 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 44 def deleted @deleted end |
#excluded ⇒ Array<String> (readonly)
48 49 50 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 48 def excluded @excluded end |
#excluded_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)
52 53 54 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 52 def excluded_contexts @excluded_contexts end |
#generation ⇒ Integer|nil (readonly)
60 61 62 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 60 def generation @generation end |
#included ⇒ Array<String> (readonly)
46 47 48 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 46 def included @included end |
#included_contexts ⇒ Array<LaunchDarkly::Impl::Model::SegmentTarget> (readonly)
50 51 52 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 50 def included_contexts @included_contexts end |
#key ⇒ String (readonly)
40 41 42 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 40 def key @key end |
#rules ⇒ Array<SegmentRule> (readonly)
54 55 56 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 54 def rules @rules end |
#salt ⇒ String (readonly)
62 63 64 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 62 def salt @salt end |
#unbounded ⇒ Boolean (readonly)
56 57 58 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 56 def unbounded @unbounded end |
#unbounded_context_kind ⇒ String (readonly)
58 59 60 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 58 def unbounded_context_kind @unbounded_context_kind end |
#version ⇒ Integer (readonly)
42 43 44 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 42 def version @version end |
Instance Method Details
#==(other) ⇒ Object
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.
67 68 69 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 67 def [](key) @data[key] end |
#as_json ⇒ Object
parameter is unused, but may be passed if we’re using the json gem
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.
80 81 82 |
# File 'lib/ldclient-rb/impl/model/segment.rb', line 80 def to_json(*a) as_json.to_json(a) end |