namespace impressionable model module class methods with 'impressionist_'

This commit is contained in:
Ross Kaffenberger 2012-03-19 14:31:05 -04:00
parent 594889a3db
commit 380f49cf62
5 changed files with 14 additions and 14 deletions

View File

@ -3,19 +3,19 @@ module Impressionist
extend ActiveSupport::Concern
module ClassMethods
attr_accessor :cache_options
@cache_options = nil
attr_accessor :impressionist_cache_options
@impressionist_cache_options = nil
def counter_cache_options
if @cache_options
def impressionist_counter_cache_options
if @impressionist_cache_options
options = { :column_name => :impressions_count, :unique => false }
options.merge!(@cache_options) if @cache_options.is_a?(Hash)
options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash)
options
end
end
def counter_caching?
counter_cache_options.present?
def impressionist_counter_caching?
impressionist_counter_cache_options.present?
end
end
@ -33,7 +33,7 @@ module Impressionist
end
def update_counter_cache
cache_options = self.class.counter_cache_options
cache_options = self.class.impressionist_counter_cache_options
column_name = cache_options[:column_name].to_sym
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
update_attribute(column_name, count)

View File

@ -10,7 +10,7 @@ class Impression < ActiveRecord::Base
def update_impressions_counter_cache
impressionable_class = self.impressionable_type.constantize
if impressionable_class.counter_cache_options
if impressionable_class.impressionist_counter_cache_options
resouce = impressionable_class.find(self.impressionable_id)
resouce.try(:update_counter_cache)
end

View File

@ -5,7 +5,7 @@ module Impressionist
module ClassMethods
def is_impressionable(options={})
has_many :impressions, :as => :impressionable, :dependent => :destroy
@cache_options = options[:counter_cache]
@impressionist_cache_options = options[:counter_cache]
end
end
end

View File

@ -8,13 +8,13 @@ describe Impression do
Impression.destroy_all
end
describe "self#counter_caching?" do
describe "self#impressionist_counter_caching?" do
it "should know when counter caching is enabled" do
Widget.should be_counter_caching
Widget.should be_impressionist_counter_caching
end
it "should know when counter caching is disabled" do
Article.should_not be_counter_caching
Article.should_not be_impressionist_counter_caching
end
end