Skip to content

Commit

Permalink
Add install task
Browse files Browse the repository at this point in the history
New meilisearch:install task creates an initializer file
  • Loading branch information
sabljak committed Aug 28, 2023
1 parent 531bf48 commit 598f789
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ Create a new file `config/initializers/meilisearch.rb` to setup your `MEILISEARC

```ruby
MeiliSearch::Rails.configuration = {
meilisearch_url: 'YourMeilisearchUrl', # example: http://localhost:7700
meilisearch_api_key: 'YourMeilisearchAPIKey',
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://localhost:7700'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'YourMeilisearchAPIKey')
}
```

Or you can run a rake task to create the initializer file for you:

```bash
bin/rails meilisearch:install
```

The gem is compatible with [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord), [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel).

⚠️ Note that even if you want to use all the default options, you must declare an empty `meilisearch` block in your model.
Expand Down
7 changes: 7 additions & 0 deletions lib/meilisearch/rails/tasks/meilisearch.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ namespace :meilisearch do

MeiliSearch::Rails::Utilities.clear_all_indexes
end

desc 'Create initializer file'
task install: :environment do
puts 'Creating initializer file'

copy_file "#{__dir__}/../templates/initializer.rb", "config/initializers/meilisearch.rb"
end
end
4 changes: 4 additions & 0 deletions lib/meilisearch/rails/templates/initializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MeiliSearch::Rails.configuration = {
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://localhost:7700'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'YourMeilisearchAPIKey')
}

0 comments on commit 598f789

Please sign in to comment.