Skip to content

Commit

Permalink
Document callbacks in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Aug 6, 2023
1 parent fac03f7 commit 50286bc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ of `Typesensual::Index` and defining your schema and how to load the data. For e
following index might be used to index movies from an ActiveRecord model:

```ruby
# app/indices/movie_index.rb
# app/indices/movies_index.rb
class MoviesIndex < Typesensual::Index
# The schema of the collection
schema do
Expand Down Expand Up @@ -97,6 +97,20 @@ class MoviesIndex < Typesensual::Index
end
```

### Integrating with your model

If you use ActiveRecord, there's a set of premade callbacks you can use:

```ruby
class Movie < ApplicationRecord
after_commit MoviesIndex.ar_callbacks, on: %i[create update destroy]
end
```

You're free to use these callbacks as-is, or you can use them as a starting point for your own
integration. They're just calling `MoviesIndex.index_one` and `MoviesIndex.remove_one` under the
hood, so you can do the same in your own callbacks or outside of ActiveRecord.

### Loading data into your index

Once you have defined your index, you can load data into it and update the alias to point to the
Expand Down

0 comments on commit 50286bc

Please sign in to comment.