From 463b515956b063a6f60f3a9b240d45d7fb86da60 Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Sat, 15 Mar 2014 20:49:33 -0700 Subject: [PATCH] Bump version to 1.1.1. Updated CHANGELOG and README. --- CHANGELOG.md | 4 ++++ README.md | 22 ++++++++++++++++++++++ lib/mongoid/magic-counter-cache/version.rb | 2 +- lib/mongoid_magic_counter_cache/version.rb | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c86704..ecd6329 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.1 + +* Add :if_update option in order to allow counter to be conditionally increment/decrement counter when an update is made to a referenced/embedded object. + ## v1.0.0 * Remove version dependency to work with rails 4. Breaks compatibility with ruby 1.9.2 and older diff --git a/README.md b/README.md index f404c03..f5dda73 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,28 @@ end comment_count will get incremented / decremented only when `:if` condition returns `true` +### Conditional Counter After Update + +In conjunction with the conditional counter, if you want to maintain counter after an update to an object, then you can specify it using `:if_update` + +Using same example as above, in the referrenced/Embedded document, add an additional condition for counter using `:if_update` + +````rb +class Comment + include Mongoid::Document + include Mongoid::MagicCounterCache + + belongs_to :post + + field :remark + field :is_published, type: Boolean, default: false + + counter_cache :post, :if => Proc.new { |act| (act.is_published) }, :if_update => Proc.new { |act| act.changes['is_published'] } +end +```` + +When a comment is saved, comment_count will get incremented / decremented if the is_published field is dirty. + ## TODO 1. Add additional options parameters diff --git a/lib/mongoid/magic-counter-cache/version.rb b/lib/mongoid/magic-counter-cache/version.rb index fb93060..b13be3c 100644 --- a/lib/mongoid/magic-counter-cache/version.rb +++ b/lib/mongoid/magic-counter-cache/version.rb @@ -1,5 +1,5 @@ module Mongoid module MagicCounterCache - VERSION = "1.1.0" + VERSION = "1.1.1" end end diff --git a/lib/mongoid_magic_counter_cache/version.rb b/lib/mongoid_magic_counter_cache/version.rb index 5752241..ecd1439 100644 --- a/lib/mongoid_magic_counter_cache/version.rb +++ b/lib/mongoid_magic_counter_cache/version.rb @@ -1,3 +1,3 @@ module MongoidMagicCounterCache - VERSION = "1.1.0" + VERSION = "1.1.1" end