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.

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



94
95
96
97
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 94

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

Instance Attribute Details

#stateString (readonly)

Returns The state.

Returns:

  • (String)

    The state



85
86
87
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 85

def state
  @state
end

#versionInteger (readonly)

Returns The version.

Returns:

  • (Integer)

    The version



88
89
90
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 88

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



156
157
158
159
160
161
162
163
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 156

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:



133
134
135
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 133

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

.no_selectorSelector

Returns an empty Selector.

Returns:



104
105
106
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 104

def self.no_selector
  Selector.new
end

Instance Method Details

#==(other) ⇒ Object



165
166
167
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 165

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)


113
114
115
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 113

def defined?
  self != Selector.no_selector
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  self == other
end

#hashObject



173
174
175
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 173

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

#nameSymbol

Returns the event name for payload transfer.

Returns:

  • (Symbol)


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

def name
  EventName::PAYLOAD_TRANSFERRED
end

#to_hHash

Serializes the Selector to a Hash.

Returns:

  • (Hash)


142
143
144
145
146
147
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 142

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