class CartonDb::SimpleMapDb

A map with strings as keys and values that can each be either a string or nil.

Data storage is in the same form as ListMapDb, but string values are stored as single-element lists and nil values are stored as empty lists. Only the first element in an entry's content is significant when retrieving a value from a multi-element underlying entry.

See the documentation for CartonDb::ListMapDb for additional details.

Attributes

list_map_db[RW]

Public Class Methods

new(name) click to toggle source

Initializes an instance that interacts with the database identified by the given name, which is the full path to a directory in the filesystem.

See the documentation for CartonDb::ListMapDb#initialize for additional details.

@param name [String] The full path of the directory in the

filesystem in which the data is stored or will be stored.
# File lib/carton_db/simple_map_db.rb, line 31
def initialize(name)
  self.list_map_db = CartonDb::ListMapDb.new(name)
end

Public Instance Methods

[](key) click to toggle source

Returns the content of the entry identified by the given key or nil if no such entry exists.

See the documentation for CartonDb::ListMapDb#initialize for performance characteristics.

@param key [String] The key identifying the entry. @return [String, nil] if a matching entry exists. @return [nil] if no matching entry exists.

# File lib/carton_db/simple_map_db.rb, line 57
def [](key)
  content = list_map_db[key]
  content&.first
end
[]=(key, value) click to toggle source

Creates a new entry or replaces the contents of the existing entry identified by the given key.

See the documentation for CartonDb::ListMapDb#initialize for performance characteristics.

@param key [String] The key identifying the entry. @param value [String, nil] The value to be stored.

# File lib/carton_db/simple_map_db.rb, line 43
def []=(key, value)
  content = value.nil? ? [] : [value.to_s]
  list_map_db[key] = content
end