mongoid-simple-tags 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+ group :development do
3
+ gem "bundler", "~> 1.0.0"
4
+ gem "jeweler", "~> 1.6.2"
5
+ gem "mongoid", ">= 2.0.2"
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.7)
5
+ activesupport (= 3.0.7)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.7)
9
+ bson (1.3.1)
10
+ builder (2.1.2)
11
+ git (1.2.5)
12
+ i18n (0.5.0)
13
+ jeweler (1.6.2)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ mongo (1.3.1)
18
+ bson (>= 1.3.1)
19
+ mongoid (2.0.2)
20
+ activemodel (~> 3.0)
21
+ mongo (~> 1.3)
22
+ tzinfo (~> 0.3.22)
23
+ rake (0.9.2)
24
+ tzinfo (0.3.27)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.0.0)
31
+ jeweler (~> 1.6.2)
32
+ mongoid (>= 2.0.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 mauro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = mongoid-simple-tags
2
+
3
+ mongoid-simple-tags is a basic and simple tagging system for mongoid using map-reduce function
4
+
5
+ == Usage
6
+
7
+ === Model
8
+
9
+ class User
10
+ include Mongoid::Document
11
+ include Mongoid::Document::Taggable
12
+ end
13
+
14
+ === Console
15
+
16
+ u = User.new(:name => "Tuquito")
17
+ u.tag_list = "linux, tucuman, free software"
18
+ u.tags # => ["linux","tucuman","free software"]
19
+ u.save
20
+
21
+ User.tagged_with("linux") # => u
22
+ User.tagged_with(["tucuman", "free software"]) # => u
23
+
24
+ u2 = User.new(:name => "ubuntu")
25
+ u2.tag_list = "linux"
26
+ u2.save
27
+
28
+ User.tagged_with("linux") # => [u, u2]
29
+
30
+
31
+ == Copyright
32
+
33
+ Copyright (c) 2011 chebyte(mauro torres). See LICENSE.txt for
34
+ further details.
35
+
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "mongoid-simple-tags"
18
+ gem.homepage = "http://github.com/chebyte/mongoid-simple-tags"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{tags on mongoid made easy}
21
+ gem.description = %Q{basic and simple tagging system for mongoid}
22
+ gem.email = "maurotorres@gmail.com"
23
+ gem.authors = ["chebyte"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency('mongoid','>=2.0.2')
26
+
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,74 @@
1
+ # Basic tagging system for mongoid documents implemented with map-reduce function.
2
+ # chebyte.com 2011
3
+ #
4
+ # class User
5
+ # include Mongoid::Document
6
+ # include Mongoid::Document::Taggable
7
+ # end
8
+ #
9
+ # u = User.new(:name => "Tuquito")
10
+ # u.tag_list = "linux, tucuman, free software"
11
+ # u.tags # => ["linux","tucuman","free software"]
12
+ # u.save
13
+ #
14
+ # User.tagged_with("linux") # => u
15
+ # User.tagged_with(["tucuman", "free software"]) # => u
16
+ #
17
+ # u2 = User.new(:name => "ubuntu")
18
+ # u2.tag_list = "linux"
19
+ # u2.save
20
+ #
21
+ # User.tagged_with("linux") # => [u, u2]
22
+
23
+ module Mongoid
24
+ module Document
25
+ module Taggable
26
+ def self.included(base)
27
+ base.class_eval do |klass|
28
+ klass.field :tags, :type => Array
29
+ klass.index :tags
30
+
31
+ klass.send :after_save, :rebuild_tags
32
+
33
+ include InstanceMethods
34
+ extend ClassMethods
35
+
36
+ end
37
+ end
38
+
39
+ module InstanceMethods
40
+ def tag_list=(tags)
41
+ self.tags = tags.split(",").collect{ |t| t.strip }.delete_if{ |t| t.blank? }
42
+ end
43
+
44
+ def tag_list
45
+ self.tags.join(", ") if tags
46
+ end
47
+
48
+ protected
49
+ def rebuild_tags
50
+ self.collection.map_reduce(
51
+ "function() { if(this.tags) this.tags.forEach(function(t){ emit(t, 1); }); }",
52
+ "function(key,values) { var count = 0; values.forEach(function(v){ count += v; }); return count; }",
53
+ { :out => 'tags' }
54
+ )
55
+ end
56
+ end
57
+
58
+ module ClassMethods
59
+
60
+ def all_tags(opts={})
61
+ tags = Mongoid.master.collection('tags')
62
+ opts.merge(:sort => ["_id", :desc]) unless opts[:sort]
63
+ tags.find({}, opts).to_a.map!{|item| { :name => item['_id'], :count => item['value'].to_i } }
64
+ end
65
+
66
+ def tagged_with(tags)
67
+ tags = [tags] unless tags.is_a? Array
68
+ any_in(tags: tags)
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
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
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'mongoid-simple-tags'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMongoidSimpleTags < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-simple-tags
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - chebyte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-12 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: jeweler
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.2
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: mongoid
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.2
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: mongoid
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.0.2
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ description: basic and simple tagging system for mongoid
61
+ email: maurotorres@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - LICENSE.txt
68
+ - README.rdoc
69
+ files:
70
+ - .document
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE.txt
74
+ - README.rdoc
75
+ - Rakefile
76
+ - VERSION
77
+ - lib/mongoid-simple-tags.rb
78
+ - test/helper.rb
79
+ - test/test_mongoid-simple-tags.rb
80
+ has_rdoc: true
81
+ homepage: http://github.com/chebyte/mongoid-simple-tags
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: -2044117358371232742
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.5.2
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: tags on mongoid made easy
111
+ test_files: []
112
+