Class: Imperium::KVPair
- Inherits:
-
Object
- Object
- Imperium::KVPair
- 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
-
#create_index ⇒ Integer
The internal index value representing when the entry was created.
-
#flags ⇒ Integer
An opaque unsigned integer for use by the client application.
-
#key ⇒ String
The full path for the entry.
-
#lock_index ⇒ Integer
The number of times this key has successfully been locked, the #session attribute indicates which session owns the lock.
-
#modify_index ⇒ Integer
The internal index value representing when the entry was last updated.
-
#session ⇒ String
The identifier for the session that owns the lock.
-
#value ⇒ String
The stored value (returned already base64 decoded).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(attributes = {}) ⇒ KVPair
constructor
Initialize a KVPair.
Constructor Details
#initialize(attributes = {}) ⇒ KVPair
Initialize a Imperium::KVPair
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_index ⇒ Integer
Returns 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 |
#flags ⇒ Integer
Returns 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 |
#key ⇒ String
Returns 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_index ⇒ Integer
Returns 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_index ⇒ Integer
Returns 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 |
#session ⇒ String
Returns 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 |
#value ⇒ String
Returns 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 |