mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-28 04:00:45 +00:00
Fold legacy has_view_count plugin into lib
This commit is contained in:
parent
c1466c262a
commit
7738c2b845
11 changed files with 34 additions and 40 deletions
|
@ -15,8 +15,6 @@
|
||||||
# text_coding :integer default(0), not null
|
# text_coding :integer default(0), not null
|
||||||
#
|
#
|
||||||
|
|
||||||
require File.join(Rails.root, 'vendor', 'plugins', 'has_view_count', 'init.rb')
|
|
||||||
|
|
||||||
class Article < ActiveRecord::Base
|
class Article < ActiveRecord::Base
|
||||||
include Exceptions
|
include Exceptions
|
||||||
include Extra
|
include Extra
|
||||||
|
|
1
lib/plugins/has_view_count/init.rb
Normal file
1
lib/plugins/has_view_count/init.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
require 'has_view_count'
|
33
lib/plugins/has_view_count/lib/has_view_count.rb
Normal file
33
lib/plugins/has_view_count/lib/has_view_count.rb
Normal file
|
@ -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)
|
1
vendor/plugins/has_view_count/init.rb
vendored
1
vendor/plugins/has_view_count/init.rb
vendored
|
@ -1 +0,0 @@
|
||||||
require File.join(Rails.root, 'vendor', 'plugins', 'has_view_count', 'lib', 'has_view_count.rb')
|
|
|
@ -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)
|
|
Loading…
Reference in a new issue