Renames plus start of docs
This commit is contained in:
parent
f2e9bcc03b
commit
da6ee085b6
|
@ -15,7 +15,7 @@ A [Pigeon Protocol](https://tildegit.org/PigeonProtocolConsortium/protocol_spec)
|
|||
* Current windows support is unknown (and unlikely to work in current state). Please report bugs.
|
||||
* Not published to RubyGems yet (see installation instructions below)
|
||||
* Single threaded use is assumed and is intended for a single user per OS process. It makes many design tradeoffs around that use case.
|
||||
* Bundling operations need performance tuning. Optimizations are planned, help is welcome.
|
||||
* Bundling operations need performance tuning. Optimizations are planned and help is welcome.
|
||||
|
||||
# Build From Source
|
||||
|
||||
|
@ -70,7 +70,7 @@ TODO
|
|||
|
||||
# Idea Bin
|
||||
|
||||
- [ ] Map/reduce plugin support for custom indices?
|
||||
- [ ] Ability to add map/reduce plugins to support custom indices?
|
||||
- [ ] Ability to add a blob in one swoop using File objects and `Message#[]=`, maybe?
|
||||
- [ ] Bundling via [Optar](http://ronja.twibright.com/optar/) or [Colorsafe](https://github.com/colorsafe/colorsafe)
|
||||
|
||||
|
|
|
@ -169,14 +169,14 @@ module Pigeon
|
|||
draft.signature = author.sign(unsigned)
|
||||
tokens = Lexer.tokenize_unsigned(unsigned, draft.signature)
|
||||
message = Parser.parse(db, tokens)[0]
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
message
|
||||
end
|
||||
|
||||
def self.update_draft(db, key, value)
|
||||
draft = db.get_draft
|
||||
draft[key] = value
|
||||
db.save_draft(draft)
|
||||
db._replace_draft(draft)
|
||||
return draft.body[key]
|
||||
end
|
||||
|
||||
|
@ -187,7 +187,7 @@ module Pigeon
|
|||
author = msg.author
|
||||
signature = msg.signature
|
||||
|
||||
return db.read_message(msg_hash) if db.message_saved?(msg_hash)
|
||||
return db.read_message(msg_hash) if db.have_message?(msg_hash)
|
||||
|
||||
if key_count > 64
|
||||
msg = MSG_SIZE_ERROR % key_count
|
||||
|
|
|
@ -37,8 +37,8 @@ module Pigeon
|
|||
store.all_messages(mhash)
|
||||
end
|
||||
|
||||
def message_saved?(multihash)
|
||||
store.message_saved?(multihash)
|
||||
def have_message?(multihash)
|
||||
store.have_message?(multihash)
|
||||
end
|
||||
|
||||
def _save_message(msg_obj)
|
||||
|
@ -81,7 +81,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
# === DRAFTS
|
||||
def reset_draft
|
||||
def delete_current_draft
|
||||
add_config(CURRENT_DRAFT, nil)
|
||||
end
|
||||
|
||||
|
@ -89,10 +89,10 @@ module Pigeon
|
|||
old = get_config(CURRENT_DRAFT)
|
||||
raise "PUBLISH OR RESET CURRENT DRAFT (#{old.kind}) FIRST" if old
|
||||
|
||||
save_draft(Draft.new(kind: kind, body: body))
|
||||
_replace_draft(Draft.new(kind: kind, body: body))
|
||||
end
|
||||
|
||||
def save_draft(draft)
|
||||
def _replace_draft(draft)
|
||||
add_config(CURRENT_DRAFT, draft)
|
||||
draft
|
||||
end
|
||||
|
@ -109,7 +109,7 @@ module Pigeon
|
|||
Helpers.update_draft(self, k, v)
|
||||
end
|
||||
|
||||
def reset_draft
|
||||
def delete_current_draft
|
||||
add_config(CURRENT_DRAFT, nil)
|
||||
end
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ module Pigeon
|
|||
end
|
||||
end
|
||||
|
||||
def message_saved?(multihash)
|
||||
def have_message?(multihash)
|
||||
read { store[MESG_NS].fetch(multihash, false) }
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
# Ruby API Follow Along Tutorial
|
||||
|
||||
## Introduction and Intended Audience
|
||||
|
||||
Pigeon is a peer-to-peer log database that serves the needs of off grid and delay-tolerant systems.
|
||||
Pigeon Ruby is a Ruby-based database client that is interoperable with other compliant Pigeon Protocol clients.
|
||||
It allows users to manage replicated, distributed log databases. Pigeon makes this possible even on systems with no internet access via sneakernet, thanks to a bundle file specification and extreme delay tolerance properties.
|
||||
|
||||
This document will teach you how to:
|
||||
|
||||
* Create and manage a database.
|
||||
* Build messages using drafts.
|
||||
* Manage and query existing messages.
|
||||
* Replicate a database among peers.
|
||||
* Go beyond simple text messages and attach files to messages.
|
||||
* Communicate with remote databases using bundle files.
|
||||
|
||||
This guide assumes you are familiar with Ruby and the Pigeon Protocol. For an introduction to the protocol, see our protocol specification [here](https://tildegit.org/PigeonProtocolConsortium/protocol_spec).
|
||||
|
||||
## Creating a Database Object
|
||||
|
||||
```ruby
|
||||
require_relative "pigeon"
|
||||
db = Pigeon::Database.new(path: "pigeon.db")
|
||||
# => #<Pigeon::Database:0x000055a1ecca45e8>
|
||||
```
|
||||
reset_database
|
||||
add_config
|
||||
get_config
|
||||
- Don't share this file (use bundles instead!)
|
||||
- Where do blobs live?
|
||||
|
||||
## Working with Drafts
|
||||
new_draft
|
||||
delete_current_draft
|
||||
update_draft
|
||||
get_draft
|
||||
publish_draft
|
||||
|
||||
## Turning Drafts Into Messages
|
||||
|
||||
## Working With Messages
|
||||
add_message
|
||||
all_messages
|
||||
read_message
|
||||
have_message?
|
||||
|
||||
## Working with Peers
|
||||
who_am_i
|
||||
add_peer
|
||||
all_peers
|
||||
remove_peer
|
||||
block_peer
|
||||
all_blocks
|
||||
peer_blocked?
|
||||
|
||||
## Querying the Database
|
||||
get_message_by_depth
|
||||
get_message_count_for
|
||||
|
||||
## Attaching Files to Messages
|
||||
add_blob
|
||||
get_blob
|
||||
|
||||
## File Based Communication via Bundles
|
||||
export_bundle
|
||||
import_bundle
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ RSpec.describe Pigeon::Draft do
|
|||
end
|
||||
|
||||
let(:message) do
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
logo = File.read("./logo.png")
|
||||
db.update_draft("a", "bar")
|
||||
|
@ -35,7 +35,7 @@ RSpec.describe Pigeon::Draft do
|
|||
end
|
||||
|
||||
it "creates a new message" do
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
hash = db.add_blob(File.read("./logo.png"))
|
||||
expectations = {
|
||||
|
|
|
@ -122,7 +122,7 @@ RSpec.describe Pigeon::Lexer do
|
|||
end
|
||||
|
||||
let(:message) do
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
db.update_draft("foo", "bar")
|
||||
db.publish_draft
|
||||
|
|
|
@ -2,14 +2,14 @@ require "spec_helper"
|
|||
require "timeout"
|
||||
|
||||
RSpec.describe Pigeon::Message do
|
||||
def reset_draft(params)
|
||||
db.reset_draft
|
||||
def another_draft(params)
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test", body: params)
|
||||
db.get_draft
|
||||
end
|
||||
|
||||
def add_message(params)
|
||||
draft = reset_draft(params)
|
||||
draft = another_draft(params)
|
||||
db.publish_draft(draft)
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe Pigeon::Message do
|
|||
|
||||
let(:draft) do
|
||||
hash = db.add_blob(File.read("./logo.png"))
|
||||
reset_draft({ "a" => "bar", "b" => hash })
|
||||
another_draft({ "a" => "bar", "b" => hash })
|
||||
end
|
||||
|
||||
let(:templated_message) { add_message({ "a" => "b" }) }
|
||||
|
@ -65,7 +65,7 @@ RSpec.describe Pigeon::Message do
|
|||
it "creates a chain of messages" do
|
||||
all = []
|
||||
0.upto(4) do |expected_depth|
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
db.update_draft("description", "Message number #{expected_depth}")
|
||||
message = db.publish_draft
|
||||
|
@ -156,7 +156,7 @@ RSpec.describe Pigeon::Message do
|
|||
WHITESPACE.map do |n|
|
||||
kind = SecureRandom.alphanumeric(8)
|
||||
kind[rand(0...8)] = n
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: kind)
|
||||
boom = -> { db.publish_draft.render }
|
||||
expect(boom).to raise_error(Pigeon::Lexer::LexError)
|
||||
|
@ -166,11 +166,12 @@ RSpec.describe Pigeon::Message do
|
|||
# This was originally a bug nooted during development
|
||||
# That caused a runaway loop in the tokenizer.
|
||||
it "handles this key: '\\nVUx0hC3'" do
|
||||
db.reset_draft
|
||||
pending("Known bug- will fix after writing docs.")
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
db.update_draft("\nVUx0hC3", "n")
|
||||
db.update_draft("n", "\nVUx0hC3")
|
||||
Timeout::timeout(1) do
|
||||
Timeout::timeout(0.5) do
|
||||
boom = -> { Pigeon::Lexer.tokenize(db.publish_draft.render) }
|
||||
expect(boom).to raise_error(Pigeon::Lexer::LexError)
|
||||
end
|
||||
|
@ -178,7 +179,7 @@ RSpec.describe Pigeon::Message do
|
|||
|
||||
it "does not allow whitespace in key names" do
|
||||
WHITESPACE.map do |n|
|
||||
db.reset_draft
|
||||
db.delete_current_draft
|
||||
db.new_draft(kind: "unit_test")
|
||||
key = SecureRandom.alphanumeric(8)
|
||||
key[rand(0...8)] = n
|
||||
|
|
36
tutorial.rb
36
tutorial.rb
|
@ -1,36 +0,0 @@
|
|||
# add_blob
|
||||
# add_config
|
||||
# add_message
|
||||
# add_peer
|
||||
# all_blocks
|
||||
# all_messages
|
||||
# all_peers
|
||||
# block_peer
|
||||
# get_blob
|
||||
# get_config
|
||||
# get_draft
|
||||
# get_message_by_depth
|
||||
# get_message_count_for
|
||||
# message_saved?
|
||||
# peer_blocked?
|
||||
# who_am_i
|
||||
# new_draft
|
||||
# import_bundle
|
||||
# publish_draft
|
||||
# read_message
|
||||
# remove_peer
|
||||
# reset_database
|
||||
# reset_draft
|
||||
# export_bundle
|
||||
# save_draft
|
||||
# update_draft
|
||||
|
||||
require_relative "lib/pigeon"
|
||||
require "pry"
|
||||
files = %w[a.gif b.gif c.gif]
|
||||
body = { "what" => "A simple bundle with a few blobs" }
|
||||
db = Pigeon::Database.new(path: "new.db")
|
||||
db.add_message("description", body)
|
||||
files.map { |file| db.add_blob(file) }
|
||||
binding.pry
|
||||
db.export_bundle("./spec/fixtures/has_blobs")
|
Loading…
Reference in New Issue