mongoid_taggable 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -54,10 +54,14 @@ p. Then your document will have the @tags@ and @tags_array@ getter and setter. @
54
54
 
55
55
  h2. Finding Objects by Tag
56
56
 
57
- p. Tagged models get a scope called @tagged_with@:
57
+ p. Tagged models get a scope called @tagged_with@, @tagged_with_all@, and @tagged_with_any@:
58
58
 
59
59
  bc.. MyModel.tagged_with('foo')
60
60
  MyModel.published.tagged_with('foo').count
61
+ MyModel.tagged_with_all('foo', 'bar')
62
+ MyModel.tagged_with_all(['foo', 'bar'])
63
+ MyModel.tagged_with_any('foo', 'bar')
64
+ MyModel.tagged_with_any(['foo', 'bar'])
61
65
 
62
66
  h2. Tags Indexing
63
67
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  require 'jeweler'
8
8
  Jeweler::Tasks.new do |gemspec|
9
9
  gemspec.name = "mongoid_taggable"
10
- gemspec.version = "0.1.5"
10
+ gemspec.version = "0.1.6"
11
11
  gemspec.summary = "Mongoid taggable behaviour"
12
12
  gemspec.description = "Mongoid Taggable provides some helpers to create taggable documents."
13
13
  gemspec.email = "wilkerlucio@gmail.com"
@@ -38,6 +38,14 @@ module Mongoid::Taggable
38
38
  self.any_in(:tags_array => [tag])
39
39
  end
40
40
 
41
+ def tagged_with_all(*tags)
42
+ self.all_in(:tags_array => tags.flatten)
43
+ end
44
+
45
+ def tagged_with_any(*tags)
46
+ self.any_in(:tags_array => tags.flatten)
47
+ end
48
+
41
49
  def tags
42
50
  db = Mongoid::Config.master
43
51
  db.collection(tags_index_collection).find.to_a.map{ |r| r["_id"] }
@@ -1,43 +1,37 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_taggable}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wilker Lucio", "Kris Kowalik"]
12
- s.date = %q{2011-04-18}
12
+ s.date = %q{2011-05-04}
13
13
  s.description = %q{Mongoid Taggable provides some helpers to create taggable documents.}
14
14
  s.email = %q{wilkerlucio@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.textile"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "LICENSE",
22
- "README.textile",
23
- "Rakefile",
24
- "init.rb",
25
- "lib/mongoid/taggable.rb",
26
- "lib/mongoid_taggable.rb",
27
- "mongoid_taggable.gemspec",
28
- "rails/init.rb",
29
- "spec/mongoid/taggable_spec.rb",
30
- "spec/spec_helper.rb"
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"
31
30
  ]
32
31
  s.homepage = %q{http://github.com/wilkerlucio/mongoid_taggable}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
32
  s.require_paths = ["lib"]
35
33
  s.rubygems_version = %q{1.7.2}
36
34
  s.summary = %q{Mongoid taggable behaviour}
37
- s.test_files = [
38
- "spec/mongoid/taggable_spec.rb",
39
- "spec/spec_helper.rb"
40
- ]
41
35
 
42
36
  if s.respond_to? :specification_version then
43
37
  s.specification_version = 3
@@ -21,10 +21,49 @@ end
21
21
 
22
22
  describe Mongoid::Taggable do
23
23
 
24
- context "finding by tag" do
25
- it "locates tagged objects" do
26
- m = MyModel.create!(:tags => "interesting,stuff")
27
- MyModel.tagged_with('interesting').include?(m).should be_true
24
+ context "finding" do
25
+ let(:model){MyModel.create!(:tags => "interesting,stuff,good,bad")}
26
+ context "by tagged_with" do
27
+ let(:models){MyModel.tagged_with('interesting')}
28
+ it "locates tagged objects" do
29
+ models.include?(model).should be_true
30
+ end
31
+ end
32
+ context "by tagged_with_all using an array" do
33
+ let(:models){MyModel.tagged_with_all(['interesting', 'good'])}
34
+ it "locates tagged objects" do
35
+ models.include?(model).should be_true
36
+ end
37
+ end
38
+ context "by tagged_with_all using strings" do
39
+ let(:models){MyModel.tagged_with_all('interesting', 'good')}
40
+ it "locates tagged objects" do
41
+ models.include?(model).should be_true
42
+ end
43
+ end
44
+ context "by tagged_with_all when tag not included" do
45
+ let(:models){MyModel.tagged_with_all('interesting', 'good', 'mcdonalds')}
46
+ it "locates tagged objects" do
47
+ models.include?(model).should be_false
48
+ end
49
+ end
50
+ context "by tagged_with_any using an array" do
51
+ let(:models){MyModel.tagged_with_any(['interesting', 'mcdonalds'])}
52
+ it "locates tagged objects" do
53
+ models.include?(model).should be_true
54
+ end
55
+ end
56
+ context "by tagged_with_any using strings" do
57
+ let(:models){MyModel.tagged_with_any('interesting', 'mcdonalds')}
58
+ it "locates tagged objects" do
59
+ models.include?(model).should be_true
60
+ end
61
+ end
62
+ context "by tagged_with_any when tag not included" do
63
+ let(:models){MyModel.tagged_with_any('hardees', 'wendys', 'mcdonalds')}
64
+ it "locates tagged objects" do
65
+ models.include?(model).should be_false
66
+ end
28
67
  end
29
68
  end
30
69
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid_taggable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wilker Lucio
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-18 00:00:00 Z
14
+ date: 2011-05-04 00:00:00 Z
15
15
  dependencies: []
16
16
 
17
17
  description: Mongoid Taggable provides some helpers to create taggable documents.
@@ -24,7 +24,6 @@ extra_rdoc_files:
24
24
  - LICENSE
25
25
  - README.textile
26
26
  files:
27
- - .gitignore
28
27
  - LICENSE
29
28
  - README.textile
30
29
  - Rakefile
@@ -39,8 +38,8 @@ homepage: http://github.com/wilkerlucio/mongoid_taggable
39
38
  licenses: []
40
39
 
41
40
  post_install_message:
42
- rdoc_options:
43
- - --charset=UTF-8
41
+ rdoc_options: []
42
+
44
43
  require_paths:
45
44
  - lib
46
45
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -62,6 +61,5 @@ rubygems_version: 1.7.2
62
61
  signing_key:
63
62
  specification_version: 3
64
63
  summary: Mongoid taggable behaviour
65
- test_files:
66
- - spec/mongoid/taggable_spec.rb
67
- - spec/spec_helper.rb
64
+ test_files: []
65
+
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- .redcar