Constantize literals for portability and DRYness
This commit is contained in:
parent
589e3d9d6a
commit
46e1a659f6
|
@ -31,8 +31,8 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
|
|||
- [X] pigeon draft current
|
||||
- [X] pigeon draft save
|
||||
- [X] pigeon bundle create
|
||||
- [ ] Use JSON.stringify() for string keys (instead of `inspect`)
|
||||
- [ ] Move literals into `Pigeon` module as constants, again.
|
||||
- [X] Use JSON.stringify() for string keys (instead of `inspect`)
|
||||
- [X] Move literals into `Pigeon` module as constants, again.
|
||||
- [ ] pigeon bundle consume
|
||||
- [ ] pigeon message find
|
||||
- [ ] pigeon message find-all
|
||||
|
|
|
@ -24,7 +24,8 @@ module Pigeon
|
|||
EMPTY_MESSAGE = "NONE"
|
||||
OUTBOX_PATH = File.join(".pigeon", "user")
|
||||
DRAFT_PLACEHOLDER = "DRAFT"
|
||||
BUNDLE_MESSAGE_SEPARATOR = "\n\n"
|
||||
CR = "\n"
|
||||
BUNDLE_MESSAGE_SEPARATOR = CR * 2
|
||||
# /MESSAGE TEMPLATE CONSTANTS
|
||||
|
||||
# Internal namespaces for PStore keys:
|
||||
|
@ -48,6 +49,9 @@ module Pigeon
|
|||
|
||||
# Error messages
|
||||
PREV_REQUIRES_SAVE = "Can't fetch `prev` on unsaved messages"
|
||||
NO_DRAFT_FOUND = "NO DRAFT FOUND"
|
||||
STRING_KEYS_ONLY = "String keys only"
|
||||
MISSING_BODY = "BODY CANT BE EMPTY"
|
||||
end
|
||||
|
||||
require_relative File.join("pigeon", "key_pair.rb")
|
||||
|
|
|
@ -10,7 +10,7 @@ module Pigeon
|
|||
.map { |multihash| s.find_message(multihash) }
|
||||
.map { |message| message.render }
|
||||
.join(BUNDLE_MESSAGE_SEPARATOR)
|
||||
File.write(file_path, content + "\n")
|
||||
File.write(file_path, content + CR)
|
||||
end
|
||||
|
||||
def self.ingest(file_path)
|
||||
|
|
|
@ -9,7 +9,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def self.current
|
||||
Pigeon::Storage.current.get_config(CURRENT_DRAFT) or raise "NO DRAFT FOUND"
|
||||
Pigeon::Storage.current.get_config(CURRENT_DRAFT) or raise NO_DRAFT_FOUND
|
||||
end
|
||||
|
||||
def self.reset_current
|
||||
|
@ -33,7 +33,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def []=(key, value)
|
||||
raise "String keys only" unless key.is_a?(String)
|
||||
raise STRING_KEYS_ONLY unless key.is_a?(String)
|
||||
|
||||
case value[0]
|
||||
when BLOB_SIGIL, MESSAGE_SIGIL, IDENTITY_SIGIL, STRING_SIGIL
|
||||
|
|
|
@ -31,7 +31,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def initialize(author:, kind:, body:, signature: nil)
|
||||
raise "BODY CANT BE EMPTY" if body.empty?
|
||||
raise MISSING_BODY if body.empty?
|
||||
@author = author
|
||||
@kind = kind
|
||||
@body = body
|
||||
|
|
|
@ -25,7 +25,7 @@ module Pigeon
|
|||
body = message.body
|
||||
depth = message.depth
|
||||
kind = message.kind
|
||||
prev = message.prev || "NONE"
|
||||
prev = message.prev || EMPTY_MESSAGE
|
||||
signature = message.signature
|
||||
|
||||
ERB.new(template).result(binding)
|
||||
|
|
Loading…
Reference in New Issue