From dd6779946d5e4b060d50688e6e9928ce8afe46c6 Mon Sep 17 00:00:00 2001 From: jgrau Date: Wed, 10 May 2017 22:02:45 +0200 Subject: [PATCH 1/2] Default counter_cache to count all impressions --- app/models/impressionist/impressionable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 7daa061..7bfd8e8 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -8,7 +8,7 @@ module Impressionist DEFAULT_CACHE ||= { :counter_cache => false, :column_name => :impressions_count, - :unique => false + :unique => :all } def impressionist_counter_cache_options From e8b470078396016708ccfc1e81fb9a2f13378800 Mon Sep 17 00:00:00 2001 From: jgrau Date: Wed, 10 May 2017 22:10:36 +0200 Subject: [PATCH 2/2] Fix counter cache filter option --- lib/impressionist/update_counters.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/impressionist/update_counters.rb b/lib/impressionist/update_counters.rb index 046f33f..a305bc5 100644 --- a/lib/impressionist/update_counters.rb +++ b/lib/impressionist/update_counters.rb @@ -42,9 +42,17 @@ module Impressionist # is_impressionable :counter_cache => true, # :unique => :any_other_filter def unique_filter - Symbol === unique ? - unique : - :ip_address + # Support `is_impressionable :counter_cache => true, :unique => true` + # defaulting to `:ip_address` for counting unique impressions. + return :ip_address if unique == true + + # Should a user try `is_impressionable :counter_cache => true, :unique => false` + # then support that as well + return :all if unique == false + + # Otherwise set the filter to either what the user supplied as the `unique` option + # or the default (`:all`) + unique end def unique