JSON-ify key / value pairs if they arent strings

This commit is contained in:
Netscape Navigator 2020-03-15 12:12:48 -05:00
parent 31daf90cdc
commit 19a9b5b627
3 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
- [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.
- [ ] pigeon bundle consume
- [ ] pigeon message find
- [ ] pigeon message find-all

11
dist/pigeon/draft.rb vendored
View File

@ -33,11 +33,20 @@ module Pigeon
end
def []=(key, value)
raise "String keys only" unless key.is_a?(String)
case value[0]
when BLOB_SIGIL, MESSAGE_SIGIL, IDENTITY_SIGIL, STRING_SIGIL
self.body[key] = value
else
self.body[key] = value.inspect
# JSON.stringify calls were done in the name of time
# and as a convinience for values like
# bools and ints
if value.is_a?(String)
self.body[key] = value.inspect
else
self.body[key] = value.to_json
end
end
self.save
return self.body[key]

View File

@ -15,7 +15,7 @@ RSpec.describe Pigeon::Message do
it "creates a bundle" do
expected_bundle = (1..10)
.to_a
.map do |n| { foo: ["bar", 123, SecureRandom.uuid].sample } end
.map do |n| { "foo" => ["bar", 123, SecureRandom.uuid].sample } end
.map do |d| create_message(d) end
.map(&:render)
.join("\n\n")