Skip to content

Commit

Permalink
Implemented Tagging.total
Browse files Browse the repository at this point in the history
  • Loading branch information
genki committed May 8, 2009
1 parent 788ea81 commit eb14d9d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dm-is-taggable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Gem::Specification.new do |s|
s.name = %q{dm-is-taggable}
s.version = "0.1.4"
s.version = "0.1.5"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Qian, Maxime Guilbot"]
s.date = %q{2009-05-08}
s.date = %q{2009-05-09}
s.description = %q{Tagging implementation for DataMapper}
s.email = ["team [a] ekohe [d] com"]
s.extra_rdoc_files = ["README.textile", "LICENSE", "TODO"]
Expand Down
8 changes: 1 addition & 7 deletions lib/dm-is-taggable/is/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ def find(options)
end

def total(options = {})
property = DataMapper::Property.new(Tagging, :"count(*)", Integer)
order = options[:order] || :desc
dir = DataMapper::Query::Direction.new(property, order)
tag_id_to_count = Tagging.aggregate(:all.count,
options.merge(:fields => [:tag_id], :order => [dir]))
tag_ids, counts = tag_id_to_count.transpose
Tag.all(:id => tag_ids).zip counts
Tagging.total(options.merge(:taggable_type => self.name))
end
end # ClassMethods

Expand Down
9 changes: 9 additions & 0 deletions lib/dm-is-taggable/is/tagging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def is_tagging(options=nil)
end

module TaggingClassMethods
def total(options = {})
property = DataMapper::Property.new(Tagging, :"count(*)", Integer)
order = options[:order] || :desc
dir = DataMapper::Query::Direction.new(property, order)
tag_id_to_count = Tagging.aggregate(:all.count,
options.merge(:fields => [:tag_id], :order => [dir]))
tag_ids, counts = tag_id_to_count.transpose
Tag.all(:id => tag_ids).zip counts
end
end

module TaggingInstanceMethods
Expand Down
2 changes: 1 addition & 1 deletion lib/dm-is-taggable/is/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DataMapper
module Is
module Taggable
VERSION = "0.1.4"
VERSION = "0.1.5"
DEPENDENCY_VERSION = ">= 0.9.6"
end
end
Expand Down

0 comments on commit eb14d9d

Please sign in to comment.