Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelvilleneuve committed Dec 11, 2023
1 parent 6e44251 commit 90da4e8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,27 @@ UsersCreated.values_grouped_by_month(stop_at: Time.now.last_month.end_of_month,
```

If you prefer you can also `include Statisfy::Model` in your model and define the counter directly on the model.
In this case you'll have to prefix APIs with `statisfy_` to avoid conflicts with ActiveRecord methods.

You'll also need to specify the `:as` option to give a name to your counter which will be used to access the value.

```ruby
class User < ApplicationRecord
include Statisfy::Model

count every: :user_created, as: :number_of_users_created
statisfy_count every: :user_created, as: :number_of_users_created
statisfy_aggregate every: :user_update, as: :average_salary, value: -> { salary }
end

User.create(name: "John Doe")
User.create(name: "John Doe", salary: 1000)
User.create(name: "John Troe", salary: 2000)

# And then get the count like this:
User.number_of_users_created.value
# => 1
# => 2

User.average_salary.value
# => 1500
```


Expand Down

0 comments on commit 90da4e8

Please sign in to comment.