From 6e44251fb1a49707585be2b67249aba3290f1802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?= Date: Mon, 11 Dec 2023 16:57:31 +0100 Subject: [PATCH] Update readme.md --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ca16e0..db0b049 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,6 @@ User.create(name: "John Doe") UsersCreated.value # => 1 - # You can also get the count for a specific month UsersCreated.value(month: Time.now) @@ -87,6 +86,23 @@ 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. + +```ruby +class User < ApplicationRecord + include Statisfy::Model + + count every: :user_created, as: :number_of_users_created +end + +User.create(name: "John Doe") + +# And then get the count like this: +User.number_of_users_created.value +# => 1 +``` + + ### Scoped counter Imagine you have a `User` model that belongs to an `Organisation` and you want to count the number of users created per organisation.