Class: Swarm::Storage::HashStorage

Inherits:
KeyValueStorage show all
Defined in:
lib/swarm/storage/hash_storage.rb

Instance Attribute Summary

Attributes inherited from KeyValueStorage

#store

Instance Method Summary collapse

Methods inherited from KeyValueStorage

#[], #[]=, #deserialize, #initialize, #load_associations, #regex_for_type, #serialize, #trace, #trace=

Constructor Details

This class inherits a constructor from Swarm::Storage::KeyValueStorage

Instance Method Details

#all_of_type(type, subtypes: true) ⇒ Object



11
12
13
14
15
16
# File 'lib/swarm/storage/hash_storage.rb', line 11

def all_of_type(type, subtypes: true)
  store.select { |key, value|
    key.match(regex_for_type(type)) &&
      (subtypes || value["type"] == type)
  }.values
end

#delete(key) ⇒ Object



18
19
20
# File 'lib/swarm/storage/hash_storage.rb', line 18

def delete(key)
  store.delete(key)
end

#ids_for_type(type) ⇒ Object



6
7
8
9
# File 'lib/swarm/storage/hash_storage.rb', line 6

def ids_for_type(type)
  keys = store.keys.select { |key| key.match(regex_for_type(type)) }
  keys.map { |key| key.gsub(regex_for_type(type), '\1') }
end

#truncateObject



22
23
24
# File 'lib/swarm/storage/hash_storage.rb', line 22

def truncate
  store.clear
end