Skip to content

Commit

Permalink
fix: Create the folder at index path when it doesn't exist
Browse files Browse the repository at this point in the history
* Fix broken spec and clarify dev setup instructions

* fix: Create the folder at index path when it doesn't exist

Co-authored-by: Alexander Baygeldin <a.baygeldin@gmail.com>
  • Loading branch information
mfkp and baygeldin authored Mar 11, 2022
1 parent 11194a3 commit c9446b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions lib/tantiny/index.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "fileutils"

module Tantiny
class Index
DEFAULT_INDEX_SIZE = 50_000_000
Expand All @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion spec/tantiny/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:tokenizer) { Tantiny::Tokenizer.default }

after do
FileUtils.remove_dir(tmpdir)
FileUtils.rm_rf(tmpdir)
end

def documents
Expand All @@ -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)

Expand Down

0 comments on commit c9446b7

Please sign in to comment.