From e3f86c80512afc7fda4c98b753c7b103331731b1 Mon Sep 17 00:00:00 2001 From: Geoff Harcourt Date: Sat, 28 Dec 2013 15:01:39 -0500 Subject: [PATCH 1/2] Only define Impressionable::ClassMethods::DEFAULT_CACHE when undefined Current behavior causes unnecessary warning messages to be issued when using Impressionist with application preloaders such as spring. --- app/models/impressionist/impressionable.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index c9159bc..76a2b9f 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -5,7 +5,13 @@ module Impressionist module ClassMethods attr_accessor :impressionist_cache_options - DEFAULT_CACHE = { :counter_cache => false, :column_name => :impressions_count, :unique => false } + unless defined?(DEFAULT_CACHE) + DEFAULT_CACHE = { + :counter_cache => false, + :column_name => :impressions_count, + :unique => false + } + end def impressionist_counter_cache_options @impressionist_cache_options ||= {} From ed00e3ffe2ced6fe41d405c7034c75764e64dff9 Mon Sep 17 00:00:00 2001 From: Geoff Harcourt Date: Tue, 31 Dec 2013 14:51:24 -0500 Subject: [PATCH 2/2] Use more concise declaration of DEFAULT_CACHE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In response to @acnalesso’s notes on e3f86c80512afc7fda4c98b753c7b103331731b1, using ||= to make assignment of Impressionable::ClassMethods::DEFAULT_CACHE more concise, avoiding a call to #defined? when checking to see if the constant has been declared. --- app/models/impressionist/impressionable.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 76a2b9f..32152cc 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -5,13 +5,11 @@ module Impressionist module ClassMethods attr_accessor :impressionist_cache_options - unless defined?(DEFAULT_CACHE) - DEFAULT_CACHE = { - :counter_cache => false, - :column_name => :impressions_count, - :unique => false - } - end + DEFAULT_CACHE ||= { + :counter_cache => false, + :column_name => :impressions_count, + :unique => false + } def impressionist_counter_cache_options @impressionist_cache_options ||= {}