mongoid_taggable 1.1.0 → 1.1.1
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.
- checksums.yaml +8 -8
- data/lib/mongoid/taggable.rb +20 -28
- data/mongoid_taggable.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGU1ODdmNDExYTQ4ZGYwNjYyNGU1MjBiNzE2ODdjNGI4ZmRjZGJhYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTA1MGJlYzllYTM1MjRjNGQ3NDc5ZWNhOWNjMDYzNDg4ZTRiOWQzYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGJmMjBiYTRmNjI1MTYwZWI0YzE3ODdjYTAwYThiODg4ZjM1Y2QyYjhhYzdm
|
10
|
+
ZmI2ODU2NzgwYjVmMmFhODQxNWE3NTEwZTY3MjhkZDMzMWY2OGY2YzBmZWRh
|
11
|
+
Y2MwNDFlZTE4YjkyZjY0OTAyNjgzNWM5M2ZmMmU5OTg4ZGUyZjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDUxMmJkYzg1ODg4ZGEzMTZjZmI5MWExYzAwZGEwODFhNWViYjIxMzIwYTJi
|
14
|
+
Yjc4ZWIzZGYyYmViNzQ0ZjVhMjMyNDRlNjU4MWY3OGQ5YWMyN2RiODA4ZWI5
|
15
|
+
MGFiMmU2NjVkZGYxYjA5YzZlYmI5YTJiMmYyNTM1OTZlNWI5MjM=
|
data/lib/mongoid/taggable.rb
CHANGED
@@ -13,26 +13,20 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module Mongoid::Taggable
|
16
|
-
|
16
|
+
extend ActiveSupport::Concern
|
17
|
+
|
18
|
+
included do
|
17
19
|
# create fields for tags and index it
|
18
|
-
|
19
|
-
|
20
|
+
field :tags_array, :type => Array, :default => []
|
21
|
+
index({ tags_array: 1 })
|
20
22
|
|
21
23
|
# add callback to save tags index
|
22
|
-
|
23
|
-
if document.tags_array_changed
|
24
|
-
document.class.save_tags_index!
|
25
|
-
document.tags_array_changed = false
|
26
|
-
end
|
24
|
+
after_save do |document|
|
25
|
+
document.class.save_tags_index! if document.tags_array_changed?
|
27
26
|
end
|
28
27
|
|
29
|
-
# extend model
|
30
|
-
base.extend ClassMethods
|
31
|
-
base.send :include, InstanceMethods
|
32
|
-
base.send :attr_accessor, :tags_array_changed
|
33
|
-
|
34
28
|
# enable indexing as default
|
35
|
-
|
29
|
+
enable_tags_index!
|
36
30
|
end
|
37
31
|
|
38
32
|
module ClassMethods
|
@@ -111,22 +105,20 @@ module Mongoid::Taggable
|
|
111
105
|
end
|
112
106
|
end
|
113
107
|
|
114
|
-
module InstanceMethods
|
115
|
-
def tags
|
116
|
-
(tags_array || []).join(self.class.tags_separator)
|
117
|
-
end
|
118
108
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
else
|
123
|
-
self.tags_array = []
|
124
|
-
end
|
125
|
-
@tags_array_changed = true
|
126
|
-
end
|
109
|
+
def tags
|
110
|
+
(tags_array || []).join(self.class.tags_separator)
|
111
|
+
end
|
127
112
|
|
128
|
-
|
129
|
-
|
113
|
+
def tags=(tags)
|
114
|
+
if tags.present?
|
115
|
+
self.tags_array = tags.split(self.class.tags_separator).map(&:strip).reject(&:blank?)
|
116
|
+
else
|
117
|
+
self.tags_array = []
|
130
118
|
end
|
131
119
|
end
|
120
|
+
|
121
|
+
def save_tags_index!
|
122
|
+
self.class.save_tags_index!
|
123
|
+
end
|
132
124
|
end
|
data/mongoid_taggable.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |g|
|
6
6
|
g.name = 'mongoid_taggable'
|
7
|
-
g.version = '1.1.
|
7
|
+
g.version = '1.1.1'
|
8
8
|
g.date = '2013-03-22'
|
9
9
|
g.description = %q{Mongoid Taggable provides some helpers to create taggable documents.}
|
10
10
|
g.summary = %q{Mongoid taggable behaviour}
|