Impressionable now extends ActiveSupport::Concern. Adds pg gem to test_app.
This commit is contained in:
parent
9321135b0b
commit
0e7d75d1ec
|
@ -1,10 +1,6 @@
|
||||||
module Impressionist
|
module Impressionist
|
||||||
module Impressionable
|
module Impressionable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
def self.included(base)
|
|
||||||
base.extend ClassMethods
|
|
||||||
base.send(:include, InstanceMethods)
|
|
||||||
end
|
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
attr_accessor :cache_options
|
attr_accessor :cache_options
|
||||||
|
@ -28,44 +24,41 @@ module Impressionist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def impressionable?
|
||||||
def impressionable?
|
true
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def impressionist_count(options={})
|
|
||||||
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
|
|
||||||
imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
|
|
||||||
if options[:filter]!=:all
|
|
||||||
imps = imps.select(options[:filter]).group(options[:filter])
|
|
||||||
end
|
|
||||||
imps.all.size
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_counter_cache
|
|
||||||
cache_options = self.class.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)
|
|
||||||
end
|
|
||||||
|
|
||||||
# OLD METHODS - DEPRECATE IN V0.5
|
|
||||||
def impression_count(start_date=nil,end_date=Time.now)
|
|
||||||
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all})
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_impression_count(start_date=nil,end_date=Time.now)
|
|
||||||
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash})
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_impression_count_ip(start_date=nil,end_date=Time.now)
|
|
||||||
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address})
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_impression_count_session(start_date=nil,end_date=Time.now)
|
|
||||||
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def impressionist_count(options={})
|
||||||
|
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
|
||||||
|
imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date])
|
||||||
|
if options[:filter]!=:all
|
||||||
|
imps = imps.select(options[:filter]).group(options[:filter])
|
||||||
|
end
|
||||||
|
imps.all.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_counter_cache
|
||||||
|
cache_options = self.class.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)
|
||||||
|
end
|
||||||
|
|
||||||
|
# OLD METHODS - DEPRECATE IN V0.5
|
||||||
|
def impression_count(start_date=nil,end_date=Time.now)
|
||||||
|
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all})
|
||||||
|
end
|
||||||
|
|
||||||
|
def unique_impression_count(start_date=nil,end_date=Time.now)
|
||||||
|
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash})
|
||||||
|
end
|
||||||
|
|
||||||
|
def unique_impression_count_ip(start_date=nil,end_date=Time.now)
|
||||||
|
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address})
|
||||||
|
end
|
||||||
|
|
||||||
|
def unique_impression_count_session(start_date=nil,end_date=Time.now)
|
||||||
|
impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,9 @@ source 'https://rubygems.org'
|
||||||
|
|
||||||
gem 'rails', '3.2.2'
|
gem 'rails', '3.2.2'
|
||||||
|
|
||||||
# Bundle edge Rails instead:
|
|
||||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
|
||||||
|
|
||||||
gem 'impressionist', :path => '../'
|
gem 'impressionist', :path => '../'
|
||||||
|
|
||||||
|
gem 'pg'
|
||||||
gem 'sqlite3'
|
gem 'sqlite3'
|
||||||
|
|
||||||
gem 'json'
|
gem 'json'
|
||||||
|
|
Loading…
Reference in New Issue