[UNSTABLE] Fix test, begin `message sign`
This commit is contained in:
parent
1232151df9
commit
a2db4e3cdd
|
@ -1,6 +1,7 @@
|
|||
module Pigeon
|
||||
class Message
|
||||
NAME_OF_DRAFT = "HEAD.draft"
|
||||
OUTBOX_PATH = File.join(".pigeon", "user")
|
||||
|
||||
attr_reader :author,
|
||||
:kind,
|
||||
|
@ -34,12 +35,36 @@ module Pigeon
|
|||
@current ||= Marshal.load(Pigeon::Storage.current.get_config(NAME_OF_DRAFT))
|
||||
end
|
||||
|
||||
def calculate_signature
|
||||
puts "========== TODO"
|
||||
"FIX_ASAP_!"
|
||||
end
|
||||
|
||||
def path_to_message_numbe(n)
|
||||
File.join(".pigeon", "user", "#{n.to_s.rjust(7, "0")}.pigeon")
|
||||
end
|
||||
|
||||
def sign
|
||||
# Set @depth
|
||||
@depth = (Dir[OUTBOX_PATH].count - 1)
|
||||
@signature = calculate_signature
|
||||
|
||||
# Create a file in ".pigeon/user/#{ @depth.rjust(7, "0") }".pigeon
|
||||
file_path = path_to_message_numbe(@depth)
|
||||
binding.pry
|
||||
# calculate prev
|
||||
@prev = "HOW WILL I DO THIS?"
|
||||
# Store to disk
|
||||
self.save
|
||||
# return self
|
||||
end
|
||||
|
||||
def save
|
||||
Pigeon::Storage.current.set_config(NAME_OF_DRAFT, Marshal.dump(self))
|
||||
self
|
||||
end
|
||||
|
||||
def serialize
|
||||
def render
|
||||
Template.new(self).render
|
||||
end
|
||||
|
||||
|
|
10
pigeon-cli
10
pigeon-cli
|
@ -76,7 +76,7 @@ module Pigeon
|
|||
desc "create", "Begin a new Pigeon message"
|
||||
|
||||
def create(kind)
|
||||
puts Pigeon::Message.create(kind: kind).serialize
|
||||
puts Pigeon::Message.create(kind: kind).render
|
||||
end
|
||||
|
||||
desc "append", "Add a key/value pair to the current DRAFT"
|
||||
|
@ -90,11 +90,17 @@ module Pigeon
|
|||
|
||||
def show(message_id = "")
|
||||
if message_id == ""
|
||||
puts Pigeon::Message.current.serialize
|
||||
puts Pigeon::Message.current.render
|
||||
else
|
||||
raise "TODO: Find message by ID?"
|
||||
end
|
||||
end
|
||||
|
||||
desc "sign", "Commit current DRAFT to local feed."
|
||||
|
||||
def sign
|
||||
puts Pigeon::Message.current.sign.render
|
||||
end
|
||||
end
|
||||
|
||||
class CLI < Thor
|
||||
|
|
|
@ -60,8 +60,11 @@ echo "...blob"
|
|||
echo "...identity"
|
||||
./pigeon-cli message append key6 \@galdahnB3L2DE2cTU0Me54IpIUKVEgKmBwvZVtWJccg=.ed25519
|
||||
|
||||
echo "show current message"
|
||||
echo "show draft message"
|
||||
./pigeon-cli message show
|
||||
|
||||
echo "sign (publish, save, commit, etc) draft message"
|
||||
./pigeon-cli message sign
|
||||
|
||||
echo "getting status:"
|
||||
./pigeon-cli status
|
||||
|
|
|
@ -2,8 +2,13 @@ require "spec_helper"
|
|||
|
||||
RSpec.describe Pigeon::Template do
|
||||
MessageShim = Struct.new(:author, :body, :kind, :depth, :prev, :signature)
|
||||
EXPECTED_DRAFT =
|
||||
"author FAKE_AUTHOR\ndepth DRAFT\nkind FAKE_KIND\nprev DRAFT\n\n\nsignature DRAFT\n\n"
|
||||
EXPECTED_DRAFT = [
|
||||
"\nauthor FAKE_AUTHOR",
|
||||
"\nkind FAKE_KIND",
|
||||
"\nprev DRAFT",
|
||||
"\ndepth DRAFT",
|
||||
"\n\n\nsignature DRAFT \n\n",
|
||||
].join("")
|
||||
it "renders a DRAFT" do
|
||||
args = ["FAKE_AUTHOR",
|
||||
nil,
|
||||
|
|
Loading…
Reference in New Issue