Class: Imperium::KVPair

Inherits:
Object
  • Object
show all
Defined in:
lib/imperium/kv_pair.rb

Overview

KVPair provides a more OO/Rubyish interface to the objects returned from the KV API on a GET request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ KVPair

Initialize a Imperium::KVPair

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes for this object as parsed from the API response.



48
49
50
51
52
# File 'lib/imperium/kv_pair.rb', line 48

def initialize(attributes = {})
  ATTRIBUTE_MAP.each do |key, attribute_name|
    send("#{attribute_name}=", attributes[key]) if attributes[key]
  end
end

Instance Attribute Details

#create_indexInteger

Returns The internal index value representing when the entry was created.

Returns:

  • (Integer)

    The internal index value representing when the entry was created.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#flagsInteger

Returns An opaque unsigned integer for use by the client application.

Returns:

  • (Integer)

    An opaque unsigned integer for use by the client application.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#keyString

Returns The full path for the entry.

Returns:

  • (String)

    The full path for the entry.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#lock_indexInteger

Returns The number of times this key has successfully been locked, the #session attribute indicates which session owns the lock.

Returns:

  • (Integer)

    The number of times this key has successfully been locked, the #session attribute indicates which session owns the lock.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#modify_indexInteger

Returns The internal index value representing when the entry was last updated.

Returns:

  • (Integer)

    The internal index value representing when the entry was last updated.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#sessionString

Returns The identifier for the session that owns the lock.

Returns:

  • (String)

    The identifier for the session that owns the lock.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

#valueString

Returns The stored value (returned already base64 decoded).

Returns:

  • (String)

    The stored value (returned already base64 decoded)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/imperium/kv_pair.rb', line 27

class KVPair
  ATTRIBUTE_MAP = {
    'LockIndex' => :lock_index,
    'Session' => :session,
    'Key' => :key,
    'Flags' => :flags,
    'Value' => :value,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index,
  }.freeze
  private_constant :ATTRIBUTE_MAP

  ATTRIBUTE_NAMES = ATTRIBUTE_MAP.values
  private_constant :ATTRIBUTE_NAMES

  attr_accessor *ATTRIBUTE_NAMES

  # Initialize a {KVPair}
  #
  # @param attributes [Hash] The attributes for this object as parsed from the
  #   API response.
  def initialize(attributes = {})
    ATTRIBUTE_MAP.each do |key, attribute_name|
      send("#{attribute_name}=", attributes[key]) if attributes[key]
    end
  end

  def ==(other)
    return false unless self.class === other
    ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
  end

  # Capture and base64 decode a value from the api.
  #
  # @param value [String] The base64 encoded value from the response.
  def value=(value)
    return @value = nil if value.nil?
    @value = Base64.decode64 value
  end
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
# File 'lib/imperium/kv_pair.rb', line 54

def ==(other)
  return false unless self.class === other
  ATTRIBUTE_NAMES.all? { |attr| self.send(attr) == other.send(attr )}
end