From 9ec6861624bf53354b259a8f61b69183f5bc34c6 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 14 May 2020 08:32:57 -0500 Subject: [PATCH] More string constants --- README.md | 1 - lib/pigeon.rb | 2 +- lib/pigeon/database.rb | 4 ++-- lib/pigeon/storage.rb | 8 ++++---- spec/pigeon/bundle_spec.rb | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3b6293f..e0b3d50 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ See `kitchen_sink.sh` examples. # Current Status - [ ] Change message templates to render headers in this order: `author`, `prev`, `lipmaa`, `depth`, `kind`. - - [ ] Make location of blob folder configurable? - [ ] Change `@`, `%`, `&` to `feed.`, `mesg.`, `blob.`, respectively. Better readability, easier onboarding, URL friendly. - [ ] Update Dev docs in protocol spec to reflect changes to `lipmaa` header. - [ ] Update spec document CLI usage examples to reflect API changes in 2020. diff --git a/lib/pigeon.rb b/lib/pigeon.rb index 55cbda1..45cab7a 100644 --- a/lib/pigeon.rb +++ b/lib/pigeon.rb @@ -10,7 +10,7 @@ module Pigeon PIGEON_DB_PATH = File.join("pigeon.db") DEFAULT_BUNDLE_PATH = File.join(Dir.pwd, "bundle") - PIGEON_BLOB_PATH = File.join(Dir.home, "pigeon_sha256") + DEFAULT_BLOB_DIR = File.join(Dir.home, "pigeon_sha256") MESSAGE_FILE = "messages.pgn" # MESSAGE TEMPLATE CONSTANTS: HEADER_TPL = "author <%= author %>\nkind <%= kind %>\nprev <%= prev %>\ndepth <%= depth %>\nlipmaa <%= lipmaa %>\n\n" diff --git a/lib/pigeon/database.rb b/lib/pigeon/database.rb index 8fc9dbc..d7a5684 100644 --- a/lib/pigeon/database.rb +++ b/lib/pigeon/database.rb @@ -161,10 +161,10 @@ module Pigeon .map do |mhash| rel_path = Helpers.hash2file_path(mhash) from = File.join([file_path] + rel_path) - to = File.join([PIGEON_BLOB_PATH] + rel_path) + to = File.join([DEFAULT_BLOB_DIR] + rel_path) if (File.file?(from) && !File.file?(to)) data = File.read(from) - Helpers.write_to_disk(PIGEON_BLOB_PATH, mhash, data) + Helpers.write_to_disk(DEFAULT_BLOB_DIR, mhash, data) end end messages diff --git a/lib/pigeon/storage.rb b/lib/pigeon/storage.rb index 28ac3fb..b0fa22a 100644 --- a/lib/pigeon/storage.rb +++ b/lib/pigeon/storage.rb @@ -67,7 +67,7 @@ module Pigeon def get_blob(blob_multihash) path1 = File.join(Helpers.hash2file_path(blob_multihash)) - path2 = File.join(PIGEON_BLOB_PATH, path1) + path2 = File.join(DEFAULT_BLOB_DIR, path1) File.read(path2) if File.file?(path2) end @@ -125,14 +125,14 @@ module Pigeon end def have_blob?(multihash) - path = File.join(PIGEON_BLOB_PATH, Helpers.hash2file_path(multihash)) + path = File.join(DEFAULT_BLOB_DIR, Helpers.hash2file_path(multihash)) File.file?(path) end private def write_to_disk(mhash, data) - Helpers.write_to_disk(PIGEON_BLOB_PATH, mhash, data) + Helpers.write_to_disk(DEFAULT_BLOB_DIR, mhash, data) end def bootstrap @@ -144,7 +144,7 @@ module Pigeon store[MESSAGE_BY_DEPTH_NS] ||= {} store[PEER_NS] ||= Set.new end - Helpers.mkdir_p(PIGEON_BLOB_PATH) + Helpers.mkdir_p(DEFAULT_BLOB_DIR) store end diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index 3919276..b0d382a 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" RSpec.describe Pigeon::Message do before(:each) do puts "WARNING: This test deletes the blob dir! Fix ASAP" - `rm -rf #{Pigeon::PIGEON_BLOB_PATH}` + `rm -rf #{Pigeon::DEFAULT_BLOB_DIR}` p = Pigeon::DEFAULT_BUNDLE_PATH File.delete(p) if File.file?(p) end