mongoid_taggable 0.1.4 → 0.1.5

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.
data/README.textile CHANGED
@@ -18,17 +18,17 @@ bc. script/plugin install git://github.com/wilkerlucio/mongoid_taggable.git
18
18
 
19
19
  h2. Basic Usage
20
20
 
21
- To make a document taggable you just need to include Mongoid::Taggable into your document:
21
+ To make a document taggable you need to include @Mongoid::Taggable@ into your document:
22
22
 
23
23
  bc.. class Post
24
24
  include Mongoid::Document
25
25
  include Mongoid::Taggable
26
-
26
+
27
27
  field :title
28
28
  field :content
29
29
  end
30
30
 
31
- p. Them in your form:
31
+ p. And in your form:
32
32
 
33
33
  bc.. <% form_for @post do |f| %>
34
34
  <p>
@@ -48,13 +48,20 @@ bc.. <% form_for @post do |f| %>
48
48
  </p>
49
49
  <% end %>
50
50
 
51
- p. In this case, the text fields for tags should receive the list of tags separated by comma (below in this document you will see how to change the separator)
51
+ p. In this case, the text fields for tags should receive the list of tags separated by comma (See below for how to change the separator).
52
+
53
+ p. Then your document will have the @tags@ and @tags_array@ getter and setter. @tags@ is as a plain string with tags separated by comma, and @tags_array@ an array representation.
54
+
55
+ h2. Finding Objects by Tag
56
+
57
+ p. Tagged models get a scope called @tagged_with@:
52
58
 
53
- p. Then your document will have the @tags@ and @tags_array@ getter and setter. The @tags@ you use as a plain string with tags separated by comma, and the @tags_array@ is an array with tags. These two properties are automatically synchronized.
59
+ bc.. MyModel.tagged_with('foo')
60
+ MyModel.published.tagged_with('foo').count
54
61
 
55
62
  h2. Tags Indexing
56
63
 
57
- This lib will automatically create an index of tags and their counts for you after saving the document, useful for getting a list of all tags used in documents of this collection or to create a tag cloud. See the following example to understand how to use it:
64
+ This module will automatically create an index of tags and their counts for you after saving the document. This can be used for a tag cloud. See the following example to understand how to use it:
58
65
 
59
66
  bc.. Post.create!(:tags => "food,ant,bee")
60
67
  Post.create!(:tags => "juice,food,bee,zip")
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.4"
10
+ gemspec.version = "0.1.5"
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"
@@ -17,30 +17,33 @@ module Mongoid::Taggable
17
17
  # create fields for tags and index it
18
18
  base.field :tags_array, :type => Array
19
19
  base.index [['tags_array', Mongo::ASCENDING]]
20
-
20
+
21
21
  # add callback to save tags index
22
22
  base.after_save do |document|
23
23
  document.class.save_tags_index!
24
24
  end
25
-
25
+
26
26
  # extend model
27
27
  base.extend ClassMethods
28
28
  base.send :include, InstanceMethods
29
-
29
+
30
30
  # enable indexing as default
31
31
  base.enable_tags_index!
32
32
  end
33
-
33
+
34
34
  module ClassMethods
35
- # get an array with all defined tags for this model, this list returns
36
- # an array of distinct ordered list of tags defined in all documents
37
- # of this model
35
+ # returns an array of distinct ordered list of tags defined in all documents
36
+
37
+ def tagged_with(tag)
38
+ self.any_in(:tags_array => [tag])
39
+ end
40
+
38
41
  def tags
39
42
  db = Mongoid::Config.master
40
43
  db.collection(tags_index_collection).find.to_a.map{ |r| r["_id"] }
41
44
  end
42
45
 
43
- # retrieve the list of tags with weight(count), this is usefull for
46
+ # retrieve the list of tags with weight (i.e. count), this is useful for
44
47
  # creating tag clouds
45
48
  def tags_with_weight
46
49
  db = Mongoid::Config.master
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_taggable}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
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-03-09}
12
+ s.date = %q{2011-04-18}
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 = [
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.homepage = %q{http://github.com/wilkerlucio/mongoid_taggable}
33
33
  s.rdoc_options = ["--charset=UTF-8"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.5.0}
35
+ s.rubygems_version = %q{1.7.2}
36
36
  s.summary = %q{Mongoid taggable behaviour}
37
37
  s.test_files = [
38
38
  "spec/mongoid/taggable_spec.rb",
@@ -20,6 +20,14 @@ class MyModel
20
20
  end
21
21
 
22
22
  describe Mongoid::Taggable do
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
28
+ end
29
+ end
30
+
23
31
  context "saving tags from plain text" do
24
32
  before :each do
25
33
  @m = MyModel.new
@@ -75,7 +83,7 @@ describe Mongoid::Taggable do
75
83
  MyModel.tags_index_collection.should == "my_models_tags_index"
76
84
  end
77
85
 
78
- context "retriving index" do
86
+ context "retrieving index" do
79
87
  before :each do
80
88
  MyModel.create!(:tags => "food,ant,bee")
81
89
  MyModel.create!(:tags => "juice,food,bee,zip")
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.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wilker Lucio
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-09 00:00:00 -03:00
15
- default_executable:
14
+ date: 2011-04-18 00:00:00 Z
16
15
  dependencies: []
17
16
 
18
17
  description: Mongoid Taggable provides some helpers to create taggable documents.
@@ -36,7 +35,6 @@ files:
36
35
  - rails/init.rb
37
36
  - spec/mongoid/taggable_spec.rb
38
37
  - spec/spec_helper.rb
39
- has_rdoc: true
40
38
  homepage: http://github.com/wilkerlucio/mongoid_taggable
41
39
  licenses: []
42
40
 
@@ -60,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  requirements: []
61
59
 
62
60
  rubyforge_project:
63
- rubygems_version: 1.5.0
61
+ rubygems_version: 1.7.2
64
62
  signing_key:
65
63
  specification_version: 3
66
64
  summary: Mongoid taggable behaviour