mongoid_taggable_on 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/lib/mongoid/taggable_on.rb +39 -0
- data/lib/mongoid_taggable_on.rb +1 -0
- metadata +61 -0
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Mongoid Taggable On
|
2
|
+
|
3
|
+
Mongoid Taggable provides some helpers to create taggable documents, can use many fields.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
You can simple install from rubygems:
|
8
|
+
|
9
|
+
gem install mongoid_taggable_on
|
10
|
+
|
11
|
+
or in Gemfile:
|
12
|
+
|
13
|
+
gem 'mongoid_taggable_on'
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
class Movie
|
18
|
+
include Mongoid::Document
|
19
|
+
include Mongoid::TaggableOn
|
20
|
+
|
21
|
+
taggable_on :actors, :index => false
|
22
|
+
taggable_on :directors
|
23
|
+
taggable_on :countries
|
24
|
+
|
25
|
+
field :title
|
26
|
+
field :summary
|
27
|
+
end
|
28
|
+
|
29
|
+
Now you can use sample:
|
30
|
+
|
31
|
+
irb> m = Movie.new
|
32
|
+
irb> m.actors_list = "Jason Statham, Joseph Gordon-Levitt, Johnny Depp, Nicolas Cage"
|
33
|
+
irb> m.actors
|
34
|
+
["Jason Statham", "Joseph Gordon-Levitt", "Johnny De", "Nicolas Cage"]
|
35
|
+
irb> m.country_list = "United States| China|Mexico"
|
36
|
+
irb> m.countries
|
37
|
+
["United States","China","Mexico"]
|
38
|
+
|
39
|
+
## Allow split chars
|
40
|
+
|
41
|
+
, ,| /
|
42
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
module TaggableOn
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def taggable_on(field_name, opts = {})
|
12
|
+
field_name = field_name.to_s.tableize
|
13
|
+
field_name_single = field_name.singularize
|
14
|
+
|
15
|
+
index_code = ""
|
16
|
+
if opts[:index] != false
|
17
|
+
index_code = "index :#{field_name}, :background => true"
|
18
|
+
end
|
19
|
+
|
20
|
+
class_eval %{
|
21
|
+
field :#{field_name}, :type => Array, :default => []
|
22
|
+
|
23
|
+
#{index_code}
|
24
|
+
|
25
|
+
def #{field_name_single}_list=(value)
|
26
|
+
if !value.blank?
|
27
|
+
self.#{field_name} = value.split(/,|,|\\/|\\|/).collect { |tag| tag.strip }.uniq
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def #{field_name_single}_list
|
32
|
+
return "" if self.#{field_name}.blank?
|
33
|
+
self.#{field_name}.join(",")
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'mongoid/taggable_on')
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_taggable_on
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: &70127184176480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70127184176480
|
25
|
+
description: Mongoid Taggable provides some helpers to create taggable documents,
|
26
|
+
can use many fields.
|
27
|
+
email:
|
28
|
+
- huacnlee@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/mongoid/taggable_on.rb
|
34
|
+
- lib/mongoid_taggable_on.rb
|
35
|
+
- README.md
|
36
|
+
homepage: https://github.com/huacnlee/mongoid_taggable_on
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.11
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Mongoid Taggable provides some helpers to create taggable documents, can
|
60
|
+
use many fields.
|
61
|
+
test_files: []
|