class JSONStore

JSONStore provides the same functionality as PStore, except it uses JSON to dump objects instead of Marshal. Example use:

store = JSONStore.new("json_store/json_test.json")
# Write
store.transaction { store["key"]="value" }
# Read
value = store.transaction { store["key"] }
puts value # prints "value"
# Dump the whole store
hash = store.transaction { store.to_h }
p hash # prints {"key" => "value"}

Constants

EMPTY_MARSHAL_CHECKSUM
EMPTY_MARSHAL_DATA

Public Instance Methods

dump(table) click to toggle source
# File lib/util/json_store.rb, line 20
def dump(table)
  table.to_json
end
empty_marshal_checksum() click to toggle source
# File lib/util/json_store.rb, line 47
def empty_marshal_checksum
  EMPTY_MARSHAL_CHECKSUM
end
empty_marshal_data() click to toggle source
# File lib/util/json_store.rb, line 44
def empty_marshal_data
  EMPTY_MARSHAL_DATA
end
load(content) click to toggle source
# File lib/util/json_store.rb, line 24
def load(content)
  JSON.parse(content)
end
marshal_dump_supports_canonical_option?() click to toggle source
# File lib/util/json_store.rb, line 38
def marshal_dump_supports_canonical_option?
  false
end
to_h() click to toggle source

Dumps the whole store to hash example: store = JSONStore.new(“my_file.json”) hash = store.transaction { store.to_h }

# File lib/util/json_store.rb, line 33
def to_h
  @table
end