genki-dm-is-taggable 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dm-is-taggable/is/taggable.rb +10 -0
- data/lib/dm-is-taggable/is/version.rb +1 -1
- data/lib/dm-is-taggable.rb +9 -7
- data/spec/integration/taggable_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
@@ -55,6 +55,16 @@ module DataMapper
|
|
55
55
|
options.merge!(:on => self, :by =>tagger, :with => tags)
|
56
56
|
Tag.find_taggables(options)
|
57
57
|
end
|
58
|
+
|
59
|
+
def total(options = {})
|
60
|
+
property = DataMapper::Property.new(Tagging, :"count(*)", Integer)
|
61
|
+
order = options[:order] || :desc
|
62
|
+
dir = DataMapper::Query::Direction.new(property, order)
|
63
|
+
tag_id_to_count = Tagging.aggregate(:all.count,
|
64
|
+
options.merge(:fields => [:tag_id], :order => [dir]))
|
65
|
+
tag_ids, counts = tag_id_to_count.transpose
|
66
|
+
Tag.all(:id => tag_ids).zip counts
|
67
|
+
end
|
58
68
|
end # ClassMethods
|
59
69
|
|
60
70
|
module TaggableInstanceMethods
|
data/lib/dm-is-taggable.rb
CHANGED
@@ -9,13 +9,15 @@ require 'dm-core'
|
|
9
9
|
require 'dm-aggregates'
|
10
10
|
|
11
11
|
# Require plugin-files
|
12
|
-
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
12
|
+
base_dir = Pathname(__FILE__).dirname.expand_path
|
13
|
+
require base_dir / 'dm-is-taggable' / 'tag_list.rb'
|
14
|
+
require base_dir / 'dm-is-taggable' / 'aggregate_patch.rb'
|
15
|
+
require base_dir / 'dm-is-taggable' / 'do_adapter_ext.rb'
|
16
|
+
require base_dir / 'dm-is-taggable' / 'is' / 'shared.rb'
|
17
|
+
require base_dir / 'dm-is-taggable' / 'is' / 'taggable.rb'
|
18
|
+
require base_dir / 'dm-is-taggable' / 'is' / 'tag.rb'
|
19
|
+
require base_dir / 'dm-is-taggable' / 'is' / 'tagging.rb'
|
20
|
+
require base_dir / 'dm-is-taggable' / 'is' / 'tagger.rb'
|
19
21
|
|
20
22
|
# Include the plugin in Resource
|
21
23
|
module DataMapper
|
@@ -285,5 +285,17 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
285
285
|
related_tags.include?([2,Tag.get("tag1")]).should be_true
|
286
286
|
related_tags.include?([2,Tag.get("tag2")]).should be_true
|
287
287
|
end
|
288
|
+
|
289
|
+
it "should be able to total tags" do
|
290
|
+
total = Picture.total(:limit => 10)
|
291
|
+
total.should be_a(Array)
|
292
|
+
total.should_not be_empty
|
293
|
+
total.each do |item|
|
294
|
+
item.should be_a(Array)
|
295
|
+
item.size.should == 2
|
296
|
+
item[0].should be_a(Tag)
|
297
|
+
item[1].should be_a(Integer)
|
298
|
+
end
|
299
|
+
end
|
288
300
|
end
|
289
301
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genki-dm-is-taggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Qian, Maxime Guilbot
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -104,7 +104,7 @@ requirements: []
|
|
104
104
|
rubyforge_project: dm-is-taggable
|
105
105
|
rubygems_version: 1.2.0
|
106
106
|
signing_key:
|
107
|
-
specification_version:
|
107
|
+
specification_version: 3
|
108
108
|
summary: Tagging implementation for DataMapper
|
109
109
|
test_files: []
|
110
110
|
|