mongoid_taggable 0.1.7 → 1.0.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/Gemfile +10 -0
- data/README.textile +1 -0
- data/Rakefile +13 -22
- data/lib/mongoid/taggable.rb +18 -7
- data/mongoid_taggable.gemspec +17 -39
- data/spec/mongoid.yml +6 -0
- data/spec/mongoid/taggable_spec.rb +16 -8
- data/spec/spec_helper.rb +2 -3
- metadata +61 -34
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWYwYTJhMzFiNDQ3ZGQ2NTdhMWM5MWFhOTEwYzFhNzRmYjA4YmM2Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGU5MWM3MDAxZTA2NDE5OGUxNzcxZmUzMzA1ZTI3Y2FhOWViMWFhZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmE4NTQyZGM3MGUwY2VkODhmMjg4N2NjYjFlYTdlOTlhNDI3MjZhY2ZhZGYy
|
10
|
+
M2NjYjQyY2EzMTU2MDc0ZjcyMjBlMGVjNzhlMmI2Yjk2N2YzNTVjMTdlZDFh
|
11
|
+
OTllYmQ3NjBiYmM3ZjQ5NTJiMTJmNmRjNTUzNTQ1N2M5M2Y1OGI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2NkOTU1NjE0ZjZhOTAxNWQ5ZjRiNjc3MzUxZjA0OTdiMWEyYWQ4NWYyOTFm
|
14
|
+
Mjk5MDE0NDVkMTE1YTNlNmViYzZiOGE2OTUzN2Y0ZjFiNzdkMDM4MjFjNmU0
|
15
|
+
Y2M3OWJkMzNhMDBlMDExMzMwMTcyMzQxNTQzOTFiZTc3ODMwNzY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -83,6 +83,7 @@ Post.tags_with_weight # will retrieve:
|
|
83
83
|
# ['zip', 1]
|
84
84
|
# ]
|
85
85
|
|
86
|
+
p. The tags index is unaffected by default_scopes. If enabled, all tags will be indexed regardless of other attribute values.
|
86
87
|
p. If you don't want to use this feature, it is good to disable it to improve performance:
|
87
88
|
|
88
89
|
bc.. class Post
|
data/Rakefile
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'rspec'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/gem_tasks'
|
6
3
|
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gemspec.description = "Mongoid Taggable provides some helpers to create taggable documents."
|
13
|
-
gemspec.email = "wilkerlucio@gmail.com"
|
14
|
-
gemspec.homepage = "http://github.com/wilkerlucio/mongoid_taggable"
|
15
|
-
gemspec.authors = ["Wilker Lucio", "Kris Kowalik"]
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
4
|
+
Bundler.setup(:default, :test)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
20
9
|
end
|
21
10
|
|
11
|
+
require 'rake'
|
12
|
+
require 'rdoc/task'
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core/rake_task'
|
22
15
|
|
23
|
-
desc '
|
16
|
+
desc 'Run specs'
|
24
17
|
task :default => :spec
|
25
18
|
|
26
|
-
|
27
|
-
spec.pattern = "spec/**/*_spec.rb"
|
28
|
-
end
|
19
|
+
RSpec::Core::RakeTask.new :spec
|
29
20
|
|
30
21
|
desc 'Generate documentation for the mongoid_taggable plugin.'
|
31
22
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
data/lib/mongoid/taggable.rb
CHANGED
@@ -16,7 +16,7 @@ module Mongoid::Taggable
|
|
16
16
|
def self.included(base)
|
17
17
|
# create fields for tags and index it
|
18
18
|
base.field :tags_array, :type => Array, :default => []
|
19
|
-
base.index [['tags_array', Mongo::ASCENDING]]
|
19
|
+
base.index tags_array: 1 #[['tags_array', Mongo::ASCENDING]]
|
20
20
|
|
21
21
|
# add callback to save tags index
|
22
22
|
base.after_save do |document|
|
@@ -51,13 +51,13 @@ module Mongoid::Taggable
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def tags
|
54
|
-
tags_index_collection.
|
54
|
+
tags_index_collection.find.to_a.map{ |r| r["_id"] }
|
55
55
|
end
|
56
56
|
|
57
57
|
# retrieve the list of tags with weight (i.e. count), this is useful for
|
58
58
|
# creating tag clouds
|
59
59
|
def tags_with_weight
|
60
|
-
tags_index_collection.
|
60
|
+
tags_index_collection.find.to_a.map{ |r| [r["_id"], r["value"]] }
|
61
61
|
end
|
62
62
|
|
63
63
|
def disable_tags_index!
|
@@ -78,7 +78,7 @@ module Mongoid::Taggable
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def tags_index_collection
|
81
|
-
|
81
|
+
@tags_index_collection ||= Moped::Collection.new(self.collection.database, tags_index_collection_name)
|
82
82
|
end
|
83
83
|
|
84
84
|
def save_tags_index!
|
@@ -104,7 +104,10 @@ module Mongoid::Taggable
|
|
104
104
|
return count;
|
105
105
|
}"
|
106
106
|
|
107
|
-
|
107
|
+
# Since map_reduce is normally lazy-executed, call 'raw'
|
108
|
+
# Should not be influenced by scoping. Let consumers worry about
|
109
|
+
# removing tags they wish not to appear in index.
|
110
|
+
self.unscoped.map_reduce(map, reduce).out(replace: tags_index_collection_name).raw
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
@@ -114,8 +117,16 @@ module Mongoid::Taggable
|
|
114
117
|
end
|
115
118
|
|
116
119
|
def tags=(tags)
|
117
|
-
|
120
|
+
if tags.present?
|
121
|
+
self.tags_array = tags.split(self.class.tags_separator).map(&:strip).reject(&:blank?)
|
122
|
+
else
|
123
|
+
self.tags_array = []
|
124
|
+
end
|
118
125
|
@tags_array_changed = true
|
119
126
|
end
|
127
|
+
|
128
|
+
def save_tags_index!
|
129
|
+
self.class.save_tags_index!
|
130
|
+
end
|
120
131
|
end
|
121
|
-
end
|
132
|
+
end
|
data/mongoid_taggable.gemspec
CHANGED
@@ -1,45 +1,23 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
4
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
5
|
+
Gem::Specification.new do |g|
|
6
|
+
g.name = 'mongoid_taggable'
|
7
|
+
g.version = '1.0.0.pre'
|
8
|
+
g.date = '2013-03-22'
|
9
|
+
g.description = %q{Mongoid Taggable provides some helpers to create taggable documents.}
|
10
|
+
g.summary = %q{Mongoid taggable behaviour}
|
11
|
+
g.authors = ['Caleb Clark', 'Adam St. John', 'Wilker Lucio', 'Kris Kowalik']
|
12
|
+
g.email = ['cclark@mobilizationlabs.com']
|
13
|
+
g.homepage = 'http://github.com/wilkerlucio/mongoid_taggable'
|
9
14
|
|
10
|
-
|
11
|
-
s.authors = ["Wilker Lucio", "Kris Kowalik"]
|
12
|
-
s.date = %q{2011-07-01}
|
13
|
-
s.description = %q{Mongoid Taggable provides some helpers to create taggable documents.}
|
14
|
-
s.email = %q{wilkerlucio@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.textile"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"LICENSE",
|
21
|
-
"README.textile",
|
22
|
-
"Rakefile",
|
23
|
-
"init.rb",
|
24
|
-
"lib/mongoid/taggable.rb",
|
25
|
-
"lib/mongoid_taggable.rb",
|
26
|
-
"mongoid_taggable.gemspec",
|
27
|
-
"rails/init.rb",
|
28
|
-
"spec/mongoid/taggable_spec.rb",
|
29
|
-
"spec/spec_helper.rb"
|
30
|
-
]
|
31
|
-
s.homepage = %q{http://github.com/wilkerlucio/mongoid_taggable}
|
32
|
-
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.7.2}
|
34
|
-
s.summary = %q{Mongoid taggable behaviour}
|
15
|
+
g.extra_rdoc_files = %w(LICENSE README.textile)
|
35
16
|
|
36
|
-
|
37
|
-
|
17
|
+
g.files = `git ls-files`.split($/)
|
18
|
+
g.test_files = g.files.grep(%r{^(test|spec|features)/})
|
19
|
+
g.require_paths = ['lib']
|
38
20
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
else
|
43
|
-
end
|
21
|
+
g.add_runtime_dependency 'rake', '>= 0'
|
22
|
+
g.add_runtime_dependency 'mongoid', '>= 3'
|
44
23
|
end
|
45
|
-
|
data/spec/mongoid.yml
ADDED
@@ -98,6 +98,18 @@ describe Mongoid::Taggable do
|
|
98
98
|
@m.tags = "repetitive,, commas, shouldn't cause,,, empty tags"
|
99
99
|
@m.tags_array.should == ["repetitive", "commas", "shouldn't cause", "empty tags"]
|
100
100
|
end
|
101
|
+
|
102
|
+
it "should clear out tags when set to nil" do
|
103
|
+
m = MyModel.create!(tags: "hey,there")
|
104
|
+
m.tags = nil
|
105
|
+
m.tags_array.should == []
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should clear out tags when set to empty string" do
|
109
|
+
m = MyModel.create!(tags: "hey,there")
|
110
|
+
m.tags = ""
|
111
|
+
m.tags_array.should == []
|
112
|
+
end
|
101
113
|
end
|
102
114
|
|
103
115
|
context "changing separator" do
|
@@ -130,11 +142,7 @@ describe Mongoid::Taggable do
|
|
130
142
|
end
|
131
143
|
|
132
144
|
it "should generate the index collection model based on model" do
|
133
|
-
MyModel.tags_index_collection.should be_a
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should generate the index collection model based on model with the collection name" do
|
137
|
-
MyModel.tags_index_collection.name.should == "my_models_tags_index"
|
145
|
+
MyModel.tags_index_collection.should be_a Moped::Collection
|
138
146
|
end
|
139
147
|
|
140
148
|
context "retrieving index" do
|
@@ -177,15 +185,15 @@ describe Mongoid::Taggable do
|
|
177
185
|
end
|
178
186
|
|
179
187
|
it 'should launch the map/reduce if index activate and tag_arrays change' do
|
180
|
-
m = MyModel.create!(:
|
188
|
+
m = MyModel.create!(:tags_array => "food,ant,bee")
|
181
189
|
m.tags = 'juice,food'
|
182
|
-
MyModel.
|
190
|
+
MyModel.should_receive(:save_tags_index!) {double("scope").as_null_object}
|
183
191
|
m.save
|
184
192
|
end
|
185
193
|
|
186
194
|
it 'should not launch the map/reduce if index activate and tag_arrays not change' do
|
187
195
|
m = MyModel.create!(:tags => "food,ant,bee")
|
188
|
-
MyModel.
|
196
|
+
MyModel.should_not_receive(:save_tags_index!)
|
189
197
|
m.save
|
190
198
|
m.name = 'hello'
|
191
199
|
m.save
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_taggable
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
7
|
+
- Caleb Clark
|
8
|
+
- Adam St. John
|
8
9
|
- Wilker Lucio
|
9
10
|
- Kris Kowalik
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3'
|
17
44
|
description: Mongoid Taggable provides some helpers to create taggable documents.
|
18
|
-
email:
|
45
|
+
email:
|
46
|
+
- cclark@mobilizationlabs.com
|
19
47
|
executables: []
|
20
|
-
|
21
48
|
extensions: []
|
22
|
-
|
23
|
-
extra_rdoc_files:
|
49
|
+
extra_rdoc_files:
|
24
50
|
- LICENSE
|
25
51
|
- README.textile
|
26
|
-
files:
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
27
55
|
- LICENSE
|
28
56
|
- README.textile
|
29
57
|
- Rakefile
|
@@ -32,34 +60,33 @@ files:
|
|
32
60
|
- lib/mongoid_taggable.rb
|
33
61
|
- mongoid_taggable.gemspec
|
34
62
|
- rails/init.rb
|
63
|
+
- spec/mongoid.yml
|
35
64
|
- spec/mongoid/taggable_spec.rb
|
36
65
|
- spec/spec_helper.rb
|
37
66
|
homepage: http://github.com/wilkerlucio/mongoid_taggable
|
38
67
|
licenses: []
|
39
|
-
|
68
|
+
metadata: {}
|
40
69
|
post_install_message:
|
41
70
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
71
|
+
require_paths:
|
44
72
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: "0"
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>'
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.1
|
57
83
|
requirements: []
|
58
|
-
|
59
84
|
rubyforge_project:
|
60
|
-
rubygems_version:
|
85
|
+
rubygems_version: 2.0.3
|
61
86
|
signing_key:
|
62
|
-
specification_version:
|
87
|
+
specification_version: 4
|
63
88
|
summary: Mongoid taggable behaviour
|
64
|
-
test_files:
|
65
|
-
|
89
|
+
test_files:
|
90
|
+
- spec/mongoid.yml
|
91
|
+
- spec/mongoid/taggable_spec.rb
|
92
|
+
- spec/spec_helper.rb
|