From 4d7a53866e57e9cfa1e45d001d6720e6a791e682 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 30 Jul 2012 17:45:26 +0800 Subject: [PATCH] Delete remaining impressionist files --- vendor/impressionist/Gemfile | 13 ---- .../models/impressionist/impressionable.rb | 62 ------------------- .../lib/generators/impressionist_generator.rb | 13 ---- .../lib/generators/templates/impression.rb | 5 -- .../mongoid/impressionist_controller.rb | 10 --- .../impressionist/lib/impressionist/engine.rb | 33 ---------- .../models/mongoid/impression.rb | 32 ---------- .../mongoid/impressionist/impressionable.rb | 52 ---------------- .../spec/models/counter_caching_spec.rb | 50 --------------- 9 files changed, 270 deletions(-) delete mode 100644 vendor/impressionist/Gemfile delete mode 100644 vendor/impressionist/app/models/impressionist/impressionable.rb delete mode 100644 vendor/impressionist/lib/generators/impressionist_generator.rb delete mode 100644 vendor/impressionist/lib/generators/templates/impression.rb delete mode 100644 vendor/impressionist/lib/impressionist/controllers/mongoid/impressionist_controller.rb delete mode 100644 vendor/impressionist/lib/impressionist/engine.rb delete mode 100644 vendor/impressionist/lib/impressionist/models/mongoid/impression.rb delete mode 100644 vendor/impressionist/lib/impressionist/models/mongoid/impressionist/impressionable.rb delete mode 100644 vendor/impressionist/test_app/spec/models/counter_caching_spec.rb diff --git a/vendor/impressionist/Gemfile b/vendor/impressionist/Gemfile deleted file mode 100644 index 42fe3e34..00000000 --- a/vendor/impressionist/Gemfile +++ /dev/null @@ -1,13 +0,0 @@ -source 'https://rubygems.org' - -platforms :jruby do - gem 'activerecord-jdbcsqlite3-adapter' - gem 'jdbc-sqlite3' - gem 'jruby-openssl' -end - -platforms :ruby, :mswin, :mingw do - gem 'sqlite3' -end - -gemspec diff --git a/vendor/impressionist/app/models/impressionist/impressionable.rb b/vendor/impressionist/app/models/impressionist/impressionable.rb deleted file mode 100644 index b4163054..00000000 --- a/vendor/impressionist/app/models/impressionist/impressionable.rb +++ /dev/null @@ -1,62 +0,0 @@ -module Impressionist - module Impressionable - extend ActiveSupport::Concern - - module ClassMethods - attr_accessor :impressionist_cache_options - @impressionist_cache_options = nil - - def impressionist_counter_cache_options - if @impressionist_cache_options - options = { :column_name => :impressions_count, :unique => false } - options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash) - options - end - end - - def impressionist_counter_caching? - impressionist_counter_cache_options.present? - end - - def counter_caching? - ::ActiveSupport::Deprecation.warn("#counter_caching? is deprecated; please use #impressionist_counter_caching? instead") - impressionist_counter_caching? - end - end - - def impressionable? - 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]) - options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) - end - - def update_impressionist_counter_cache - 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 - old_count = send(column_name) || 0 - self.class.update_counters(id, column_name => (count - old_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 diff --git a/vendor/impressionist/lib/generators/impressionist_generator.rb b/vendor/impressionist/lib/generators/impressionist_generator.rb deleted file mode 100644 index 008f1ecf..00000000 --- a/vendor/impressionist/lib/generators/impressionist_generator.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Impressionist - module Generators - class ImpressionistGenerator < Rails::Generators::Base - hook_for :orm - source_root File.expand_path('../templates', __FILE__) - - def copy_config_file - template 'impression.rb', 'config/initializers/impression.rb' - end - - end - end -end diff --git a/vendor/impressionist/lib/generators/templates/impression.rb b/vendor/impressionist/lib/generators/templates/impression.rb deleted file mode 100644 index 5de89e47..00000000 --- a/vendor/impressionist/lib/generators/templates/impression.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Use this hook to configure impressionist parameters -Impressionist.setup do |config| - # Define ORM. Could be :active_record (default), :mongo_mapper or :mongoid - # config.orm = :active_record -end diff --git a/vendor/impressionist/lib/impressionist/controllers/mongoid/impressionist_controller.rb b/vendor/impressionist/lib/impressionist/controllers/mongoid/impressionist_controller.rb deleted file mode 100644 index 426c5b86..00000000 --- a/vendor/impressionist/lib/impressionist/controllers/mongoid/impressionist_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}| - # creates a statment hash that contains default values for creating an impression. - # if :impressionable_id is a valid ObjectId then convert it into one - base = (defined? Moped) ? Moped::BSON : BSON - query_params.reverse_merge!( - :impressionable_type => controller_name.singularize.camelize, - :impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id]) - ) - associative_create_statement(query_params) -end \ No newline at end of file diff --git a/vendor/impressionist/lib/impressionist/engine.rb b/vendor/impressionist/lib/impressionist/engine.rb deleted file mode 100644 index fddb04f9..00000000 --- a/vendor/impressionist/lib/impressionist/engine.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "impressionist" -require "rails" - -module Impressionist - class Engine < Rails::Engine - initializer 'impressionist.model' do |app| - require "#{root}/app/models/impressionist/impressionable.rb" - if Impressionist.orm == :active_record && defined? ActiveRecord - require "impressionist/models/active_record/impression.rb" - require "impressionist/models/active_record/impressionist/impressionable.rb" - ActiveRecord::Base.send(:include, Impressionist::Impressionable) - elsif Impressionist.orm == :mongo_mapper - require "impressionist/models/mongo_mapper/impression.rb" - require "impressionist/models/mongo_mapper/impressionist/impressionable.rb" - MongoMapper::Document.plugin Impressionist::Impressionable - elsif Impressionist.orm == :mongoid - require 'impressionist/models/mongoid/impression.rb' - require 'impressionist/models/mongoid/impressionist/impressionable.rb' - Mongoid::Document.send(:include, Impressionist::Impressionable) - end - end - - initializer 'impressionist.controller' do - if Impressionist.orm == :mongoid - require 'impressionist/controllers/mongoid/impressionist_controller.rb' - end - ActiveSupport.on_load(:action_controller) do - include ImpressionistController::InstanceMethods - extend ImpressionistController::ClassMethods - end - end - end -end diff --git a/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb b/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb deleted file mode 100644 index 5c107857..00000000 --- a/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb +++ /dev/null @@ -1,32 +0,0 @@ -class Impression - include Mongoid::Document - include Mongoid::Timestamps - - attr_accessible :impressionable_type, :impressionable_field, :impressionable_id, :user_id, - :controller_name, :action_name, :view_name, :request_hash, :ip_address, - :session_hash, :message, :referrer - - belongs_to :impressionable, polymorphic: true - - field :user_id - field :controller_name - field :action_name - field :view_name - field :request_hash - field :ip_address - field :session_hash - field :message - field :referrer - - set_callback(:create, :after) do |doc| - unless impressionable_id.nil? - impressionable_class = doc.impressionable_type.constantize - - if impressionable_class.impressionist_counter_cache_options - resource = impressionable_class.find(doc.impressionable_id) - resource.try(:update_impressionist_counter_cache) - end - end - end - -end diff --git a/vendor/impressionist/lib/impressionist/models/mongoid/impressionist/impressionable.rb b/vendor/impressionist/lib/impressionist/models/mongoid/impressionist/impressionable.rb deleted file mode 100644 index 5f04b03e..00000000 --- a/vendor/impressionist/lib/impressionist/models/mongoid/impressionist/impressionable.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Impressionist - module Impressionable - extend ActiveSupport::Concern - - module ClassMethods - def is_impressionable(options={}) - has_many :impressions, as: :impressionable, dependent: :destroy - @impressionist_cache_options = options[:counter_cache] - if !@impressionist_cache_options.nil? - opts = impressionist_counter_cache_options - field opts[:column_name], type: Integer - end - end - - def impressionist_counter_cache_options - if @impressionist_cache_options - options = { :column_name => :impressions_count, :unique => false } - options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash) - options - end - end - - def impressionist_counter_caching? - impressionist_counter_cache_options.present? - end - - def counter_caching? - ::ActiveSupport::Deprecation.warn("#counter_caching? is deprecated; please use #impressionist_counter_caching? instead") - impressionist_counter_caching? - end - end - - def impressionable? - 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.between(created_at: options[:start_date]..options[:end_date]) - options[:filter] == :all ? imps.count : imps.where(options[:filter].ne => nil).count - end - - def update_impressionist_counter_cache - 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 - old_count = send(column_name) || 0 - self.inc(column_name, (count - old_count)) - end - - end -end \ No newline at end of file diff --git a/vendor/impressionist/test_app/spec/models/counter_caching_spec.rb b/vendor/impressionist/test_app/spec/models/counter_caching_spec.rb deleted file mode 100644 index 2f9636d4..00000000 --- a/vendor/impressionist/test_app/spec/models/counter_caching_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -describe Impression do - fixtures :widgets - - before(:each) do - @widget = Widget.find(1) - Impression.destroy_all - end - - describe "self#impressionist_counter_caching?" do - it "should know when counter caching is enabled" do - Widget.should be_impressionist_counter_caching - end - - it "should know when counter caching is disabled" do - Article.should_not be_impressionist_counter_caching - end - end - - describe "self#counter_caching?" do - it "should know when counter caching is enabled" do - ActiveSupport::Deprecation.should_receive(:warn) - Widget.should be_counter_caching - end - - it "should know when counter caching is disabled" do - ActiveSupport::Deprecation.should_receive(:warn) - Article.should_not be_counter_caching - end - - end - - describe "#update_impressionist_counter_cache" do - it "should update the counter cache column to reflect the correct number of impressions" do - lambda { - @widget.impressions.create(:request_hash => 'abcd1234') - @widget.reload - }.should change(@widget, :impressions_count).from(0).to(1) - end - - it "should not update the timestamp on the impressable" do - lambda { - @widget.impressions.create(:request_hash => 'abcd1234') - @widget.reload - }.should_not change(@widget, :updated_at) - end - end - -end