mongoid_taggable_on 0.1.3 → 0.1.4
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.md +40 -25
- data/lib/mongoid/taggable_on.rb +14 -14
- metadata +10 -6
data/README.md
CHANGED
@@ -10,43 +10,58 @@ Mongoid Taggable provides some helpers to create taggable documents, can use man
|
|
10
10
|
|
11
11
|
You can simple install from rubygems:
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
```bash
|
14
|
+
gem install mongoid_taggable_on
|
15
|
+
```
|
16
|
+
|
15
17
|
or in Gemfile:
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
```ruby
|
20
|
+
gem 'mongoid_taggable_on'
|
21
|
+
```
|
22
|
+
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
[中文介绍去这里](http://huacnlee.com/blog/new_gem_mongoid_taggable_on)
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Movie
|
29
|
+
include Mongoid::Document
|
30
|
+
include Mongoid::TaggableOn
|
31
|
+
|
32
|
+
taggable_on :actors, :index => false
|
33
|
+
taggable_on :directors
|
34
|
+
taggable_on :countries
|
35
|
+
|
36
|
+
field :title
|
37
|
+
field :summary
|
38
|
+
end
|
39
|
+
```
|
32
40
|
|
33
41
|
Now you can use sample:
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
```bash
|
44
|
+
irb> m = Movie.new
|
45
|
+
irb> m.actors_list = "Jason Statham, Joseph Gordon-Levitt, Johnny Depp, Nicolas Cage"
|
46
|
+
irb> m.actors
|
47
|
+
["Jason Statham", "Joseph Gordon-Levitt", "Johnny De", "Nicolas Cage"]
|
48
|
+
irb> m.country_list = "United States| China|Mexico"
|
49
|
+
irb> m.countries
|
50
|
+
["United States","China","Mexico"]
|
51
|
+
```
|
42
52
|
|
43
53
|
find with tag:
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
55
|
+
```bash
|
56
|
+
irb> Movie.tagged_with_on(:actors, "Jason Statham, Joseph Gordon-Levitt")
|
57
|
+
irb> Movie.tagged_with_on(:actors, "Jason Statham, Joseph Gordon-Levitt", :match => :any)
|
58
|
+
irb> Movie.tagged_with_on(:actors, "Nicolas Cage", :match => :not)
|
59
|
+
```
|
48
60
|
|
49
61
|
## Allow split chars
|
50
62
|
|
51
63
|
, ,| /
|
52
64
|
|
65
|
+
## Who used that?
|
66
|
+
|
67
|
+
In [720p.so](http://720p.so), the Movie actors, directors, languages, countries, tags all base in mongoid\_taggable\_on.
|
data/lib/mongoid/taggable_on.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Mongoid
|
3
3
|
module TaggableOn
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
included do
|
7
7
|
=begin rdoc
|
8
8
|
find items with tag
|
@@ -12,13 +12,13 @@ find items with tag
|
|
12
12
|
* field_name tagged field
|
13
13
|
* tags match value, allow String or Array, case insensitive, for example: "Ruby,Python" or ["Ruby","Python"] or "ruby"
|
14
14
|
* match (any,all,not) match type, default: all
|
15
|
-
|
15
|
+
|
16
16
|
*Usage*
|
17
17
|
|
18
18
|
Person.tagged_with_on(:skills, "ui design, photograph")
|
19
19
|
Person.tagged_with_on(:skills, "ui design, photograph").tagged_with_on(:languages, "english,chinese")
|
20
20
|
Person.tagged_with_on(:skills, "ui design, photograph").paginate(:page => params[:page])
|
21
|
-
|
21
|
+
|
22
22
|
=end
|
23
23
|
scope :tagged_with_on, Proc.new { |field_name, tags, opts|
|
24
24
|
return [] if field_name.blank?
|
@@ -38,9 +38,9 @@ find items with tag
|
|
38
38
|
end
|
39
39
|
}
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
module ClassMethods
|
43
|
-
|
43
|
+
|
44
44
|
=begin rdoc
|
45
45
|
=Define a tag field
|
46
46
|
*For example:*
|
@@ -60,33 +60,33 @@ find items with tag
|
|
60
60
|
field :skills, :type => Array, :default => []
|
61
61
|
def skill_list; end
|
62
62
|
def skill_list=(value); end
|
63
|
-
|
63
|
+
|
64
64
|
*Params*
|
65
65
|
|
66
66
|
* field_name <em>name for tag field</em>
|
67
67
|
* opts[:index] <em>(true/false) allow create index in MongoDB, default: true</em>
|
68
|
-
|
68
|
+
|
69
69
|
=end
|
70
70
|
def taggable_on(field_name, opts = {})
|
71
71
|
field_name = field_name.to_s.tableize
|
72
72
|
field_name_single = field_name.singularize
|
73
|
-
|
73
|
+
|
74
74
|
index_code = ""
|
75
75
|
if opts[:index] != false
|
76
|
-
index_code = "index
|
76
|
+
index_code = "index({#{field_name}: 1}, {background: true})"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
class_eval %{
|
80
80
|
field :#{field_name}, :type => Array, :default => []
|
81
|
-
|
81
|
+
|
82
82
|
#{index_code}
|
83
|
-
|
83
|
+
|
84
84
|
def #{field_name_single}_list=(value)
|
85
85
|
if !value.blank?
|
86
86
|
self.#{field_name} = self.class.split_tag(value)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def #{field_name_single}_list
|
91
91
|
return "" if self.#{field_name}.blank?
|
92
92
|
self.#{field_name}.join(",")
|
@@ -102,7 +102,7 @@ find items with tag
|
|
102
102
|
end
|
103
103
|
}
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def split_tag(value)
|
107
107
|
value.split(/,|,|\/|\|/).collect { |tag| tag.strip }.uniq
|
108
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_taggable_on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
25
30
|
description: Mongoid Taggable provides some helpers to create taggable documents,
|
26
31
|
can use many fields.
|
27
32
|
email:
|
@@ -53,10 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
58
|
version: '0'
|
54
59
|
requirements: []
|
55
60
|
rubyforge_project:
|
56
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.24
|
57
62
|
signing_key:
|
58
63
|
specification_version: 3
|
59
64
|
summary: Mongoid Taggable provides some helpers to create taggable documents, can
|
60
65
|
use many fields.
|
61
66
|
test_files: []
|
62
|
-
has_rdoc:
|