diff --git a/README.md b/README.md index d46634f..8e601bc 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ You may have noticed that `search` method returns only documents ids. This is by ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake build` to build native extensions, and then `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. We use [conventional commits](https://www.conventionalcommits.org) to automatically generate the CHANGELOG, bump the semantic version, and to publish and release the gem. All you need to do is stick to the convention and [CI will take care of everything else](https://github.com/baygeldin/tantiny/blob/main/.github/workflows/release.yml) for you. diff --git a/lib/tantiny/index.rb b/lib/tantiny/index.rb index b5fb8f3..4a70d06 100644 --- a/lib/tantiny/index.rb +++ b/lib/tantiny/index.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "fileutils" + module Tantiny class Index DEFAULT_INDEX_SIZE = 50_000_000 @@ -9,6 +11,8 @@ def self.new(path, **options, &block) index_size = options[:size] || DEFAULT_INDEX_SIZE default_tokenizer = options[:tokenizer] || Tokenizer.default + FileUtils.mkdir_p(path) + schema = Schema.new(default_tokenizer, &block) object = __new( diff --git a/spec/tantiny/index_spec.rb b/spec/tantiny/index_spec.rb index 9c191d4..c81e499 100644 --- a/spec/tantiny/index_spec.rb +++ b/spec/tantiny/index_spec.rb @@ -10,7 +10,7 @@ let(:tokenizer) { Tantiny::Tokenizer.default } after do - FileUtils.remove_dir(tmpdir) + FileUtils.rm_rf(tmpdir) end def documents @@ -28,6 +28,14 @@ def commit_and_reload expect(Dir.entries(tmpdir)).not_to be_empty end + context "when folder at path does not exist" do + it "creates it first" do + FileUtils.rm_rf(tmpdir) + expect { Tantiny::Index.new(tmpdir) {} }.not_to raise_error + expect(Dir.entries(tmpdir)).not_to be_empty + end + end + it "creates schema" do schema = Tantiny::Schema.new(tokenizer, &schema_block)