Constantize sigils

This commit is contained in:
Netscape Navigator 2019-12-04 18:17:36 -06:00
parent e260fc7bb0
commit 7223906613
4 changed files with 7 additions and 4 deletions

BIN
db.pigeon

Binary file not shown.

5
dist/pigeon.rb vendored
View File

@ -29,7 +29,10 @@ module Pigeon
BLCK_NS = "blocked"
# ^ Internal namespaces for PStore keys
BLOB_HEADER = "&"
BLOB_SIGIL = "&"
SIGNATURE_SIGIL = "%"
IDENTITY_SIGIL = "@"
STRING_SIGIL = "\""
BLOB_FOOTER = ".sha256"
end

View File

@ -38,7 +38,7 @@ module Pigeon
puts "TODO: Add #readonly? method and disallow edits after save"
# TODO: Sanitize, validate inputs.
case value[0]
when "%", "@", "&", "\"" # TODO: Use constants, not literals.
when BLOB_SIGIL, SIGNATURE_SIGIL, IDENTITY_SIGIL, STRING_SIGIL
self.body[key] = value
else
self.body[key] = value.inspect

View File

@ -32,11 +32,11 @@ module Pigeon
store[BLOB_NS][hex_digest] = data
end
[BLOB_HEADER, hex_digest, BLOB_FOOTER].join("")
[BLOB_SIGIL, hex_digest, BLOB_FOOTER].join("")
end
def get_blob(hex_digest)
hd = hex_digest.gsub(BLOB_HEADER, "").gsub(BLOB_FOOTER, "")
hd = hex_digest.gsub(BLOB_SIGIL, "").gsub(BLOB_FOOTER, "")
store.transaction(true) do
store[BLOB_NS] ||= {}
store[BLOB_NS][hd]