Cleanup
This commit is contained in:
parent
f76ee47b7a
commit
d8225bf96d
|
@ -6,11 +6,34 @@ require "securerandom"
|
|||
# Remove this when we launch or add ENVs:
|
||||
require "pry"
|
||||
|
||||
require_relative File.join("pigeon", "config.rb")
|
||||
module Pigeon
|
||||
HEADER, FOOTER = ["@", ".ed25519"]
|
||||
SEED_CONFIG_KEY = "SEED"
|
||||
VERSION = "0.0.1"
|
||||
TPL_DIR = "views"
|
||||
|
||||
PIGEON_DB_PATH = File.join("db.pigeon")
|
||||
# MESSAGE TEMPLATE CONSTANTS:
|
||||
HEADER_TPL = File.read(File.join(TPL_DIR, "1_header.erb")).sub("\n", "")
|
||||
BODY_TPL = File.read(File.join(TPL_DIR, "2_body.erb")).sub("\n", "")
|
||||
FOOTER_TPL = File.read(File.join(TPL_DIR, "3_footer.erb")).sub("\n", "")
|
||||
COMPLETE_TPL = [HEADER_TPL, BODY_TPL, FOOTER_TPL].join("")
|
||||
# /MESSAGE TEMPLATE CONSTANTS
|
||||
|
||||
# Internal namespaces for PStore keys:
|
||||
ROOT_NS = ".pigeon"
|
||||
CONF_NS = "conf"
|
||||
BLOB_NS = "blobs"
|
||||
PEER_NS = "peers"
|
||||
USER_NS = "user"
|
||||
BLCK_NS = "blocked"
|
||||
# ^ Internal namespaces for PStore keys
|
||||
|
||||
BLOB_HEADER = "&"
|
||||
BLOB_FOOTER = ".sha256"
|
||||
end
|
||||
|
||||
require_relative File.join("pigeon", "key_pair.rb")
|
||||
require_relative File.join("pigeon", "storage.rb")
|
||||
require_relative File.join("pigeon", "template.rb")
|
||||
require_relative File.join("pigeon", "message.rb")
|
||||
|
||||
module Pigeon
|
||||
end
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
module Pigeon
|
||||
module Config
|
||||
VERSION = "0.0.1"
|
||||
end
|
||||
end
|
|
@ -3,9 +3,6 @@ module Pigeon
|
|||
# help us maintain our sanity when the Gem's API
|
||||
# changes.
|
||||
class KeyPair
|
||||
HEADER, FOOTER = ["@", ".ed25519"]
|
||||
SEED_CONFIG_KEY = "SEED"
|
||||
|
||||
def self.strip_headers(identity)
|
||||
identity.sub(HEADER, "").sub(FOOTER, "")
|
||||
end
|
||||
|
@ -15,8 +12,8 @@ module Pigeon
|
|||
end
|
||||
|
||||
def self.current
|
||||
storage = Pigeon::Storage.current
|
||||
self.new(storage.get_config(SEED_CONFIG_KEY))
|
||||
key = Pigeon::Storage.current.get_config(SEED_CONFIG_KEY)
|
||||
key ? self.new(key) : self.new
|
||||
end
|
||||
|
||||
# `seed` is a 32-byte seed value from which
|
||||
|
@ -44,6 +41,7 @@ module Pigeon
|
|||
|
||||
def save!
|
||||
Pigeon::Storage.current.set_config(SEED_CONFIG_KEY, @seed)
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -34,6 +34,8 @@ module Pigeon
|
|||
end
|
||||
|
||||
def append(key, value)
|
||||
puts "TODO: Add #[] / #[]= methods"
|
||||
puts "TODO: Add #readonly? method and disallow edits after save"
|
||||
# TODO: Sanitize, validate inputs.
|
||||
case value[0]
|
||||
when "%", "@", "&", "\"" # TODO: Use constants, not literals.
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
require "strscan"
|
||||
|
||||
module Pigeon
|
||||
class Token
|
||||
attr_reader :kind
|
||||
attr_accessor :content
|
||||
|
||||
def initialize(kind)
|
||||
@kind = kind
|
||||
end
|
||||
end
|
||||
|
||||
class Parser
|
||||
def initialize(string)
|
||||
puts "THIS CLASS IS AN EXPERIMENT"
|
||||
puts "I MIGHT DELETE IT LATER."
|
||||
@scanner = StringScanner.new(string)
|
||||
# @scanner.peek
|
||||
# @scanner.scan_until
|
||||
# @scanner.getch
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,18 +2,6 @@ require "pstore"
|
|||
|
||||
module Pigeon
|
||||
class Storage
|
||||
PIGEON_DB_PATH = File.join("db.pigeon")
|
||||
|
||||
ROOT_NS = ".pigeon"
|
||||
CONF_NS = "conf"
|
||||
BLOB_NS = "blobs"
|
||||
PEER_NS = "peers"
|
||||
USER_NS = "user"
|
||||
BLCK_NS = "blocked"
|
||||
|
||||
BLOB_HEADER = "&"
|
||||
BLOB_FOOTER = ".sha256"
|
||||
|
||||
def self.current
|
||||
@current ||= self.new
|
||||
end
|
||||
|
|
|
@ -4,14 +4,6 @@ module Pigeon
|
|||
# Wrapper around a message to perform string templating.
|
||||
# Renders a string that is a Pigeon-compliant message.
|
||||
class Template
|
||||
TPL_DIR = "views"
|
||||
|
||||
HEADER_TPL = File.read(File.join(TPL_DIR, "1_header.erb")).sub("\n", "")
|
||||
BODY_TPL = File.read(File.join(TPL_DIR, "2_body.erb")).sub("\n", "")
|
||||
FOOTER_TPL = File.read(File.join(TPL_DIR, "3_footer.erb")).sub("\n", "")
|
||||
|
||||
COMPLETE_TPL = [HEADER_TPL, BODY_TPL, FOOTER_TPL].join("")
|
||||
|
||||
attr_reader :message
|
||||
|
||||
def initialize(message)
|
||||
|
|
|
@ -11,7 +11,7 @@ module Pigeon
|
|||
desc "new", "Creates a new identiy in `.pigeon` directory if none exists"
|
||||
|
||||
def new
|
||||
if File.file?(Pigeon::Storage::PIGEON_DB_PATH)
|
||||
if File.file?(Pigeon::PIGEON_DB_PATH)
|
||||
puts "Pigeon has detected a `pigeon.db` file.
|
||||
Refusing to overwrite existing Pigeon config.
|
||||
Remove config dir or switch to a different directory."
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe Pigeon::Config do
|
||||
it "has a `::VERSION`" do
|
||||
expect(Pigeon::Config::VERSION).to eq("0.0.1")
|
||||
end
|
||||
end
|
|
@ -25,9 +25,9 @@ RSpec.describe Pigeon::KeyPair do
|
|||
it "strips headers" do
|
||||
whatever = "af697f3063d46fe9546f651c08c378f8"
|
||||
example = [
|
||||
Pigeon::KeyPair::HEADER,
|
||||
Pigeon::HEADER,
|
||||
whatever,
|
||||
Pigeon::KeyPair::FOOTER,
|
||||
Pigeon::FOOTER,
|
||||
].join("")
|
||||
result = Pigeon::KeyPair.strip_headers(example)
|
||||
expect(result).to eq(whatever)
|
||||
|
@ -35,7 +35,7 @@ RSpec.describe Pigeon::KeyPair do
|
|||
|
||||
it "saves to disk" do
|
||||
argss = [
|
||||
Pigeon::KeyPair::SEED_CONFIG_KEY,
|
||||
Pigeon::SEED_CONFIG_KEY,
|
||||
FAKE_SEED,
|
||||
]
|
||||
lol = receive(:set_config).with(*argss).and_call_original
|
||||
|
|
|
@ -8,5 +8,7 @@ RSpec.describe Pigeon::Message do
|
|||
expect(message.body).to eq({})
|
||||
expect(message.depth).to eq(0)
|
||||
expect(message.prev).to eq(Pigeon::Message::EMPTY_MESSAGE)
|
||||
expect(Pigeon::Message.current).to eq(message)
|
||||
message.append("foo", "bar")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ RSpec.describe Pigeon::Storage do
|
|||
IDS = %w(@_TlC2z3FT4fimecC4eytrBhOwhLUZsVBZEZriBO9cWs=.ed25519
|
||||
@28FyT7evjcYrrwngr8G2V1HZ0ODK0VPsFctDEZwfZJc=.ed25519)
|
||||
let(:s) do
|
||||
FileUtils.rm_r(Pigeon::Storage::PIGEON_DB_PATH)
|
||||
FileUtils.rm_r(Pigeon::PIGEON_DB_PATH)
|
||||
Pigeon::Storage.current
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue