Class: LaunchDarkly::Interfaces::DataSystem::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/interfaces/data_system.rb

Overview

Selector represents a particular snapshot of data.

This type is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is not suitable for production usage.

Do not use it. You have been warned.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state: "", version: 0) ⇒ Selector

Returns a new instance of Selector.

Parameters:

  • state (String) (defaults to: "")

    The state

  • version (Integer) (defaults to: 0)

    The version



130
131
132
133
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 130

def initialize(state: "", version: 0)
  @state = state
  @version = version
end

Instance Attribute Details

#stateString (readonly)

Returns The state.

Returns:

  • (String)

    The state



121
122
123
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 121

def state
  @state
end

#versionInteger (readonly)

Returns The version.

Returns:

  • (Integer)

    The version



124
125
126
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 124

def version
  @version
end

Class Method Details

.from_h(data) ⇒ Selector

Deserializes a Selector from a Hash.

Parameters:

  • data (Hash)

    The hash representation

Returns:

Raises:

  • (ArgumentError)

    if required fields are missing



192
193
194
195
196
197
198
199
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 192

def self.from_h(data)
  state = data['state'] || data[:state]
  version = data['version'] || data[:version]

  raise ArgumentError, "Missing required fields in Selector" if state.nil? || version.nil?

  Selector.new(state: state, version: version)
end

.new_selector(state, version) ⇒ Selector

Creates a new Selector from a state string and version.

Parameters:

  • state (String)

    The state

  • version (Integer)

    The version

Returns:



169
170
171
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 169

def self.new_selector(state, version)
  Selector.new(state: state, version: version)
end

.no_selectorSelector

Returns an empty Selector.

Returns:



140
141
142
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 140

def self.no_selector
  Selector.new
end

Instance Method Details

#==(other) ⇒ Object



201
202
203
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 201

def ==(other)
  other.is_a?(Selector) && @state == other.state && @version == other.version
end

#defined?Boolean

Returns true if the Selector has a value.

Returns:

  • (Boolean)


149
150
151
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 149

def defined?
  self != Selector.no_selector
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 205

def eql?(other)
  self == other
end

#hashObject



209
210
211
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 209

def hash
  [@state, @version].hash
end

#nameString

Returns the event name for payload transfer.

Returns:

  • (String)


158
159
160
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 158

def name
  EventName::PAYLOAD_TRANSFERRED
end

#to_hHash

Serializes the Selector to a Hash.

Returns:

  • (Hash)


178
179
180
181
182
183
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 178

def to_h
  {
    state: @state,
    version: @version,
  }
end