Skip to content

Commit

Permalink
Bump version to 1.1.1. Updated CHANGELOG and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Chen committed Mar 16, 2014
1 parent 4c9deeb commit 463b515
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/magic-counter-cache/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Mongoid
module MagicCounterCache
VERSION = "1.1.0"
VERSION = "1.1.1"
end
end
2 changes: 1 addition & 1 deletion lib/mongoid_magic_counter_cache/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MongoidMagicCounterCache
VERSION = "1.1.0"
VERSION = "1.1.1"
end

0 comments on commit 463b515

Please sign in to comment.