From 7738c2b84537187b4f420d3090bb461517817c8b Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sun, 23 Aug 2015 15:43:40 +0100 Subject: [PATCH] Fold legacy has_view_count plugin into lib --- app/models/article.rb | 2 - .../plugins/has_view_count/MIT-LICENSE | 0 .../plugins/has_view_count/README.textile | 0 .../has_view_count_generator.rb | 0 .../has_view_count/templates/migration.rb | 0 .../has_view_count/templates/model.rb | 0 .../has_view_count/has_view_count.gemspec | 0 lib/plugins/has_view_count/init.rb | 1 + .../has_view_count/lib/has_view_count.rb | 33 +++++++++++++++++ vendor/plugins/has_view_count/init.rb | 1 - .../has_view_count/lib/has_view_count.rb | 37 ------------------- 11 files changed, 34 insertions(+), 40 deletions(-) rename {vendor => lib}/plugins/has_view_count/MIT-LICENSE (100%) rename {vendor => lib}/plugins/has_view_count/README.textile (100%) rename {vendor => lib}/plugins/has_view_count/generators/has_view_count/has_view_count_generator.rb (100%) rename {vendor => lib}/plugins/has_view_count/generators/has_view_count/templates/migration.rb (100%) rename {vendor => lib}/plugins/has_view_count/generators/has_view_count/templates/model.rb (100%) rename {vendor => lib}/plugins/has_view_count/has_view_count.gemspec (100%) create mode 100644 lib/plugins/has_view_count/init.rb create mode 100644 lib/plugins/has_view_count/lib/has_view_count.rb delete mode 100644 vendor/plugins/has_view_count/init.rb delete mode 100644 vendor/plugins/has_view_count/lib/has_view_count.rb diff --git a/app/models/article.rb b/app/models/article.rb index 979b8ea..21c84ad 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -15,8 +15,6 @@ # text_coding :integer default(0), not null # -require File.join(Rails.root, 'vendor', 'plugins', 'has_view_count', 'init.rb') - class Article < ActiveRecord::Base include Exceptions include Extra diff --git a/vendor/plugins/has_view_count/MIT-LICENSE b/lib/plugins/has_view_count/MIT-LICENSE similarity index 100% rename from vendor/plugins/has_view_count/MIT-LICENSE rename to lib/plugins/has_view_count/MIT-LICENSE diff --git a/vendor/plugins/has_view_count/README.textile b/lib/plugins/has_view_count/README.textile similarity index 100% rename from vendor/plugins/has_view_count/README.textile rename to lib/plugins/has_view_count/README.textile diff --git a/vendor/plugins/has_view_count/generators/has_view_count/has_view_count_generator.rb b/lib/plugins/has_view_count/generators/has_view_count/has_view_count_generator.rb similarity index 100% rename from vendor/plugins/has_view_count/generators/has_view_count/has_view_count_generator.rb rename to lib/plugins/has_view_count/generators/has_view_count/has_view_count_generator.rb diff --git a/vendor/plugins/has_view_count/generators/has_view_count/templates/migration.rb b/lib/plugins/has_view_count/generators/has_view_count/templates/migration.rb similarity index 100% rename from vendor/plugins/has_view_count/generators/has_view_count/templates/migration.rb rename to lib/plugins/has_view_count/generators/has_view_count/templates/migration.rb diff --git a/vendor/plugins/has_view_count/generators/has_view_count/templates/model.rb b/lib/plugins/has_view_count/generators/has_view_count/templates/model.rb similarity index 100% rename from vendor/plugins/has_view_count/generators/has_view_count/templates/model.rb rename to lib/plugins/has_view_count/generators/has_view_count/templates/model.rb diff --git a/vendor/plugins/has_view_count/has_view_count.gemspec b/lib/plugins/has_view_count/has_view_count.gemspec similarity index 100% rename from vendor/plugins/has_view_count/has_view_count.gemspec rename to lib/plugins/has_view_count/has_view_count.gemspec diff --git a/lib/plugins/has_view_count/init.rb b/lib/plugins/has_view_count/init.rb new file mode 100644 index 0000000..2aac8a6 --- /dev/null +++ b/lib/plugins/has_view_count/init.rb @@ -0,0 +1 @@ +require 'has_view_count' diff --git a/lib/plugins/has_view_count/lib/has_view_count.rb b/lib/plugins/has_view_count/lib/has_view_count.rb new file mode 100644 index 0000000..c963f9a --- /dev/null +++ b/lib/plugins/has_view_count/lib/has_view_count.rb @@ -0,0 +1,33 @@ +module Citrus + module HasViewCount + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def has_view_count + has_many :view_counts, :as => :viewable, :dependent => :destroy + + include Citrus::HasViewCount::InstanceMethods + end + end + + module InstanceMethods + def record_view_count(ip_address, logged_in = false) + self.view_counts.create(:viewable => self, :ip_address => ip_address, :logged_in => logged_in) + return self + end + + def view_count + self.view_counts.length + end + + def view_count_string(str = "view") + return "#{view_count} #{str.singularize}" if view_count == 1 + return "#{view_count} #{str.pluralize}" unless view_count == 1 + end + end + end +end + +ActiveRecord::Base.send(:include, Citrus::HasViewCount) diff --git a/vendor/plugins/has_view_count/init.rb b/vendor/plugins/has_view_count/init.rb deleted file mode 100644 index c73fea3..0000000 --- a/vendor/plugins/has_view_count/init.rb +++ /dev/null @@ -1 +0,0 @@ -require File.join(Rails.root, 'vendor', 'plugins', 'has_view_count', 'lib', 'has_view_count.rb') \ No newline at end of file diff --git a/vendor/plugins/has_view_count/lib/has_view_count.rb b/vendor/plugins/has_view_count/lib/has_view_count.rb deleted file mode 100644 index a524bb3..0000000 --- a/vendor/plugins/has_view_count/lib/has_view_count.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Citrus - module HasViewCount - - def self.included(base) - base.extend(ClassMethods) - end - - module ClassMethods - - def has_view_count - has_many :view_counts, :as => :viewable, :dependent => :destroy - include Citrus::HasViewCount::InstanceMethods - end - - end - - module InstanceMethods - - def record_view_count(ip_address, logged_in = false) - self.view_counts.create(:viewable => self, :ip_address => ip_address, :logged_in => logged_in) - return self - end - - def view_count - self.view_counts.length - end - - def view_count_string(str = "view") - return "#{view_count} #{str.singularize}" if view_count == 1 - return "#{view_count} #{str.pluralize}" unless view_count == 1 - end - - end - - end -end -ActiveRecord::Base.send(:include, Citrus::HasViewCount) \ No newline at end of file