Module: ActsAsViewable::ClassMethods

Defined in:
lib/acts_as_viewable/acts_as_viewable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_viewable(options = {}) ⇒ Object

Options:

:ttl   The minimum number of minutes between viewings of a specific viewable by a specific IP in order for the viewings to be considered distinct


11
12
13
14
15
16
17
18
# File 'lib/acts_as_viewable/acts_as_viewable.rb', line 11

def acts_as_viewable(options = {})
  include InstanceMethods      
  options = { :ttl => 60 }.merge(options)
  const_set('VIEWING_TIME_TO_LIVE', options[:ttl])
  has_many :viewings, :as => :viewable, :class_name => 'ActsAsViewable::Viewing'
  has_one :total_viewings, :conditions => { :viewable_type => self.name }, :as => :viewable, :class_name => 'ActsAsViewable::TotalViewings'
  named_scope :most_viewed, lambda { |*args| { :include => :total_viewings, :order => '`total_viewings`.`viewings` DESC', :limit => args.first || 10 } }
end