diff --git a/README.md b/README.md index 3fd757b..604f2a7 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`. - [X] Make all methods private except those required for the CLI. - [X] Add Lipmaa links like the Bamboo folks do. - [X] Set a max message size. + - [ ] Update README.md. Needs user manual for new `Pigeon::Database` class. - [ ] Make the switch to LevelDB, RocksDB, [UNQLite](https://unqlite.org/features.html) or similar (currently using Ruby PStore). - [ ] Make CLI names consistent with API names. Eg: find vs. read. - [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes. diff --git a/dist/pigeon.rb b/dist/pigeon.rb index 131284f..8422fbf 100644 --- a/dist/pigeon.rb +++ b/dist/pigeon.rb @@ -170,4 +170,4 @@ require_relative File.join("pigeon", "message.rb") require_relative File.join("pigeon", "draft.rb") require_relative File.join("pigeon", "lexer.rb") require_relative File.join("pigeon", "parser.rb") -require_relative File.join("pigeon", "bundle.rb") +require_relative File.join("pigeon", "database.rb") diff --git a/dist/pigeon/bundle.rb b/dist/pigeon/database.rb similarity index 69% rename from dist/pigeon/bundle.rb rename to dist/pigeon/database.rb index f6d9fd1..6b5b0cd 100644 --- a/dist/pigeon/bundle.rb +++ b/dist/pigeon/database.rb @@ -1,6 +1,9 @@ module Pigeon - class Bundle - def self.create(file_path = DEFAULT_BUNDLE_PATH) + class Database + def initialize + end + + def create_bundle(file_path = DEFAULT_BUNDLE_PATH) s = Pigeon::Storage.current content = s .find_all(Pigeon::LocalIdentity.current.multihash) @@ -11,10 +14,10 @@ module Pigeon File.write(file_path, content + CR) end - def self.ingest(file_path = DEFAULT_BUNDLE_PATH) + def ingest_bundle(file_path = DEFAULT_BUNDLE_PATH) bundle = File.read(file_path) tokens = Pigeon::Lexer.tokenize(bundle) - Pigeon::Parser.parse(tokens) #.map(&:save!) + Pigeon::Parser.parse(tokens) end end end diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index e98a50f..92988fb 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -8,6 +8,8 @@ RSpec.describe Pigeon::Message do Pigeon::LocalIdentity.reset end + let(:db) do Pigeon::Database.new end + def create_fake_messages (1..10) .to_a @@ -17,14 +19,14 @@ RSpec.describe Pigeon::Message do it "creates a bundle" do expected_bundle = create_fake_messages.map(&:render).join("\n\n") + "\n" - Pigeon::Bundle.create + db.create_bundle actual_bundle = File.read(Pigeon::DEFAULT_BUNDLE_PATH) expect(expected_bundle).to eq(actual_bundle) end it "does not crash when ingesting old messages" do create_fake_messages - Pigeon::Bundle.create - Pigeon::Bundle.ingest + db.create_bundle + db.ingest_bundle end end diff --git a/spec/pigeon/parser_spec.rb b/spec/pigeon/parser_spec.rb index f5098be..defda68 100644 --- a/spec/pigeon/parser_spec.rb +++ b/spec/pigeon/parser_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Pigeon::Lexer do Pigeon::LocalIdentity.reset end + let(:db) { Pigeon::Database.new } let(:example_bundle) { File.read("./spec/fixtures/normal.bundle") } let(:tokens) { Pigeon::Lexer.tokenize(example_bundle) } @@ -30,7 +31,7 @@ RSpec.describe Pigeon::Lexer do end it "ingests and reconstructs a bundle" do - messages = Pigeon::Bundle.ingest("./spec/fixtures/normal.bundle") + messages = db.ingest_bundle("./spec/fixtures/normal.bundle") expect(messages.length).to eq(10) expect(messages.map(&:class).uniq).to eq([Pigeon::Message]) re_bundled = messages.map(&:render).join("\n\n") + "\n" diff --git a/spec/pigeon/storage_spec.rb b/spec/pigeon/storage_spec.rb index a41ed38..a8883aa 100644 --- a/spec/pigeon/storage_spec.rb +++ b/spec/pigeon/storage_spec.rb @@ -10,9 +10,8 @@ RSpec.describe Pigeon::Storage do Pigeon::LocalIdentity.reset end - let(:s) do - Pigeon::Storage.current - end + let(:s) { Pigeon::Storage.current } + let(:db) { Pigeon::Database.new } it "sets a config" do s.set_config("FOO", "BAR") @@ -51,7 +50,7 @@ RSpec.describe Pigeon::Storage do end it "finds all authored by a particular feed" do - ingested_messages = Pigeon::Bundle.ingest("./spec/fixtures/normal.bundle") + ingested_messages = db.ingest_bundle("./spec/fixtures/normal.bundle") author = ingested_messages.first.author.multihash actual_messages = Pigeon::Storage.current.find_all(author) search_results = Pigeon::Storage.current.find_all(author)