class Swarm::Storage::KeyValueStorage

Attributes

store[R]

Public Class Methods

new(store) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 6
def initialize(store)
  @store = store
end

Public Instance Methods

[](key) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 51
def [](key)
  deserialize(store[key])
end
[]=(key, value) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 55
def []=(key, value)
  store[key] = serialize(value)
end
all_of_type(type) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 26
def all_of_type(type)
  raise "Not implemented yet!"
end
delete(key) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 59
def delete(key)
  raise "Not implemented yet!"
end
deserialize(value) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 46
def deserialize(value)
  return nil if value.nil?
  JSON.parse(value)
end
ids_for_type(type) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 22
def ids_for_type(type)
  raise "Not implemented yet!"
end
load_associations(association_name, owner:, type:, foreign_key: nil) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 30
def load_associations(association_name, owner:, type:, foreign_key: nil)
  type = type.split("::").last
  local_association_ids = :"#{association_name}_ids"
  if owner.respond_to?(local_association_ids)
    ids = owner.send(local_association_ids) || []
    ids.map { |id|
      self["#{type}:#{id}"]
    }.compact
  end
end
regex_for_type(type) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 18
def regex_for_type(type)
  /^#{type}\:(.*)/
end
serialize(value) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 41
def serialize(value)
  return nil if value.nil?
  value.to_json
end
trace() click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 10
def trace
  self["trace"]
end
trace=(traced) click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 14
def trace=(traced)
  self["trace"] = traced
end
truncate() click to toggle source
# File lib/swarm/storage/key_value_storage.rb, line 63
def truncate
  raise "Not implemented yet!"
end