Pigeon-Ruby/lib/pigeon/message.rb

48 lines
985 B
Ruby
Raw Normal View History

2019-10-21 02:11:16 +00:00
require "digest"
module Pigeon
class Message
attr_reader :author, :kind, :body, :signature, :depth, :lipmaa, :prev
2020-03-27 12:48:17 +00:00
2019-12-05 03:56:47 +00:00
def render
template.render.chomp
2019-10-19 18:14:09 +00:00
end
def multihash
2020-04-25 15:11:25 +00:00
tpl = render
digest = Digest::SHA256.digest(tpl)
sha256 = Helpers.b32_encode(digest)
"#{MESSAGE_SIGIL}#{sha256}#{BLOB_FOOTER}"
end
def initialize(author:,
kind:,
body:,
depth:,
prev:,
lipmaa:,
2020-04-18 14:37:43 +00:00
signature:)
raise MISSING_BODY if body.empty?
2020-04-25 15:11:25 +00:00
@author = author
@body = body
@depth = depth
@kind = kind
@prev = prev || Pigeon::NOTHING
@lipmaa = lipmaa
@signature = signature
2020-04-18 19:51:10 +00:00
taint
2019-12-30 02:16:42 +00:00
end
def template
MessageSerializer.new(self)
2019-10-22 01:35:48 +00:00
end
def collect_blobs
([kind] + body.keys + body.values)
.select { |x| x.match? Lexer::BLOB_VALUE }
.uniq
end
end
end