Rename *_conf to *_config, add `timestamp` to ::Message initializer.

This commit is contained in:
Netscape Navigator 2019-10-12 15:40:16 -05:00
parent 999af42410
commit b439746cf5
7 changed files with 18 additions and 20 deletions

View File

@ -16,7 +16,7 @@ module Pigeon
def self.current
storage = Pigeon::Storage.current
self.new(storage.get_conf(SEED_CONFIG_KEY))
self.new(storage.get_config(SEED_CONFIG_KEY))
end
# `seed` is a 32-byte seed value from which
@ -38,7 +38,7 @@ module Pigeon
end
def save!
Pigeon::Storage.current.set_conf(SEED_CONFIG_KEY, @seed)
Pigeon::Storage.current.set_config(SEED_CONFIG_KEY, @seed)
end
end
end

View File

@ -10,11 +10,16 @@ module Pigeon
:timestamp, # Maybe not?
:signature # Maybe not?
def initialize(author:, kind:, previous: nil, body: [])
def initialize(author:,
kind:,
previous: nil,
body: [],
timestamp: Time.now.to_i)
@author = author
@kind = kind
@previous = previous
@body = body
@timestamp = timestamp
end
def self.create(kind:, previous: nil, body: [])
@ -24,13 +29,7 @@ module Pigeon
previous: previous,
body: body)
# Save to disk as HEAD
Pigeon::Storage.set_config(NAME_OF_DRAFT, msg.dump)
end
protected
def dump
string = Marshal.dump(self)
Pigeon::Storage.current.set_config(NAME_OF_DRAFT, Marshal.dump(msg))
end
end
end

View File

@ -24,14 +24,14 @@ module Pigeon
end
end
def set_conf(key, value)
def set_config(key, value)
path = conf_path_for(key)
maybe_touch(path)
File.write(path, value.to_s)
end
def get_conf(key)
def get_config(key)
File.read(conf_path_for(key))
end

View File

@ -76,11 +76,7 @@ module Pigeon
desc "create", "Begin a new Pigeon message"
def create(kind)
raise "TODO: FIXME"
puts Pigeon::Message.create(
kind: "???",
author: "???",
)
puts Pigeon::Message.create(kind: kind)
end
end

View File

@ -37,5 +37,8 @@ echo "blocking peers:"
echo "listing all peers:"
./pigeon-cli peer all
echo "Making a new `scratch_pad` log entry"
./pigeon-cli message create scratch_pad
echo "getting status:"
./pigeon-cli status

View File

@ -30,7 +30,7 @@ RSpec.describe Pigeon::KeyPair do
FAKE_SEED,
]
FakeFS.with_fresh do
lol = receive(:set_conf).with(*argss).and_call_original
lol = receive(:set_config).with(*argss).and_call_original
expect(Pigeon::Storage.current).to lol
kp.save!
new_kp = Pigeon::KeyPair.current

View File

@ -14,8 +14,8 @@ RSpec.describe Pigeon::Storage do
it "manages configs" do
test_fs do |s|
s.set_conf("FOO", "BAR")
value = s.get_conf("FOO")
s.set_config("FOO", "BAR")
value = s.get_config("FOO")
expect(value).to eq("BAR")
end
end