Sha256: 4281a94183e93f21543905bad6e62476d03e1c019d423da531161121979a7239

Contents?: true

Size: 862 Bytes

Versions: 10

Compression:

Stored size: 862 Bytes

Contents

# Adds methods to enable tracking tags through a common polymorphic association
module ActsAsTaggableOn
  class Tag
    def self.most_hit(since=nil, limit=5)
      query = Tagging.scoped.
        joins('INNER JOIN punches ON (taggings.taggable_id = punches.punchable_id AND taggings.taggable_type = punches.punchable_type)').
        group(:tag_id).
        order('SUM(punches.hits) DESC').
        limit(limit)
      query = query.where('punches.average_time >= ?', since) if since
      query.map(&:tag)
    end

    def hits(since=nil)
      query = Tagging.scoped.
        joins('INNER JOIN punches ON (taggings.taggable_id = punches.punchable_id AND taggings.taggable_type = punches.punchable_type)').
        where(:tag_id => self.id)
      query = query.where('punches.average_time >= ?', since) if since
      query.sum('punches.hits')
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
punching_bag-0.7.0 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.6.1 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.6.0 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.4.0 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.9 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.8 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.7 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.6 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.5 lib/punching_bag/acts_as_taggable_on.rb
punching_bag-0.3.4 lib/punching_bag/acts_as_taggable_on.rb