JSON-ify key / value pairs if they arent strings
This commit is contained in:
parent
31daf90cdc
commit
19a9b5b627
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue