Class: Immudb::KVMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/immudb/kv_metadata.rb

Constant Summary collapse

DELETED_ATTR_CODE =
0
EXPIRES_AT_ATTR_CODE =
1
NON_INDEXABLE_ATTR_CODE =
2

Instance Method Summary collapse

Constructor Details

#initializeKVMetadata

Returns a new instance of KVMetadata.



19
20
21
22
# File 'lib/immudb/kv_metadata.rb', line 19

def initialize
  @attributes = {}
  @readonly = false
end

Instance Method Details

#as_deleted(deleted) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/immudb/kv_metadata.rb', line 24

def as_deleted(deleted)
  if @readonly
    raise Error, "Read-only"
  elsif !deleted
    @attributes.delete(DELETED_ATTR_CODE)
  else
    @attributes[DELETED_ATTR_CODE] = nil
  end
end

#as_non_indexable(non_indexable) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/immudb/kv_metadata.rb', line 61

def as_non_indexable(non_indexable)
  if @readonly
    raise Error, "Read-only"
  elsif !non_indexable
    @attributes.delete(NON_INDEXABLE_ATTR_CODE)
  else
    @attributes[NON_INDEXABLE_ATTR_CODE] = nil
  end
end

#bytesObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/immudb/kv_metadata.rb', line 75

def bytes
  b = "".b
  [DELETED_ATTR_CODE, EXPIRES_AT_ATTR_CODE, NON_INDEXABLE_ATTR_CODE].each do |attr_code|
    if @attributes.key?(attr_code)
      b += [attr_code].pack("C")
      if attr_code == EXPIRES_AT_ATTR_CODE
        b += [@attributes[attr_code].to_i].pack("Q>")
      end
    end
  end
  b
end

#deleted?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/immudb/kv_metadata.rb', line 34

def deleted?
  @attributes.key?(DELETED_ATTR_CODE)
end

#expirable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/immudb/kv_metadata.rb', line 49

def expirable?
  @attributes.key?(EXPIRES_AT_ATTR_CODE)
end

#expiration_timeObject



53
54
55
56
57
58
59
# File 'lib/immudb/kv_metadata.rb', line 53

def expiration_time
  if @attributes.key?(EXPIRES_AT_ATTR_CODE)
    @attributes[EXPIRES_AT_ATTR_CODE]
  else
    raise Error, "Non-expirable"
  end
end

#expires_at(expires_at) ⇒ Object



38
39
40
41
42
43
# File 'lib/immudb/kv_metadata.rb', line 38

def expires_at(expires_at)
  if @readonly
    raise Error, "Read-only"
  end
  @attributes[EXPIRES_AT_ATTR_CODE] = expires_at
end

#non_expirableObject



45
46
47
# File 'lib/immudb/kv_metadata.rb', line 45

def non_expirable
  @attributes.delete(EXPIRES_AT_ATTR_CODE)
end

#non_indexable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/immudb/kv_metadata.rb', line 71

def non_indexable?
  @attributes.key?(NON_INDEXABLE_ATTR_CODE)
end