vidibus-category_tag 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +13 -1
- data/Rakefile +0 -8
- data/app/models/tag_category.rb +50 -13
- data/lib/vidibus/category_tag/mongoid.rb +37 -14
- data/lib/vidibus/category_tag/version.rb +1 -1
- metadata +149 -133
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,18 @@ This gem is part of [Vidibus](http://vidibus.org), an open source toolset for bu
|
|
6
6
|
|
7
7
|
Add `gem "vidibus-category_tag"` to your Gemfile. Then call `bundle install` on your console.
|
8
8
|
|
9
|
+
|
10
|
+
## TODO
|
11
|
+
|
12
|
+
### Housekeeping
|
13
|
+
|
14
|
+
A task that removes delected tag categories from tagged items would be helpful. And we need a way to remove unused tags from categories.
|
15
|
+
|
16
|
+
### MapReduce
|
17
|
+
|
18
|
+
Use MapReduce to determine which tags have been used on a category. Also track the number of occurences per tag.
|
19
|
+
|
20
|
+
|
9
21
|
## Copyright
|
10
22
|
|
11
|
-
© 2011 Andre Pankratz, Martin Jagusch. See LICENSE for details.
|
23
|
+
© 2011-212 Andre Pankratz, Martin Jagusch. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -8,12 +8,6 @@ Bundler::GemHelper.install_tasks
|
|
8
8
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
9
9
|
require 'vidibus/category_tag/version'
|
10
10
|
|
11
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
12
|
-
t.pattern = 'spec/**/*_spec.rb'
|
13
|
-
t.rcov = true
|
14
|
-
t.rcov_opts = ['--exclude', '^spec,/gems/']
|
15
|
-
end
|
16
|
-
|
17
11
|
Rake::RDocTask.new do |rdoc|
|
18
12
|
rdoc.rdoc_dir = 'rdoc'
|
19
13
|
rdoc.title = "vidibus-category_tag #{Vidibus::CategoryTag::VERSION}"
|
@@ -21,5 +15,3 @@ Rake::RDocTask.new do |rdoc|
|
|
21
15
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
16
|
rdoc.options << '--charset=utf-8'
|
23
17
|
end
|
24
|
-
|
25
|
-
task :default => :rcov
|
data/app/models/tag_category.rb
CHANGED
@@ -5,27 +5,64 @@ class TagCategory
|
|
5
5
|
|
6
6
|
field :label
|
7
7
|
field :callname
|
8
|
-
field :context, :type => Array
|
9
|
-
field :tags, :type => Array
|
10
|
-
field :position, :type => Integer
|
8
|
+
field :context, :type => Array, :default => []
|
9
|
+
field :tags, :type => Array, :default => []
|
10
|
+
field :position, :type => Integer
|
11
11
|
|
12
|
-
|
12
|
+
before_validation :set_callname, :if => :label
|
13
|
+
before_validation :cleanup_tags, :if => :tags
|
14
|
+
before_create :set_position
|
13
15
|
|
14
|
-
|
16
|
+
validates :label, :callname, :presence => true
|
15
17
|
|
16
18
|
scope :sorted, order_by([:position, :asc])
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
index [:position, 1]
|
21
|
+
index [
|
22
|
+
[:context, 1],
|
23
|
+
[:callname, 1]
|
24
|
+
]
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def context(context_hash)
|
28
|
+
return all if context_hash.blank?
|
29
|
+
all_in(:context => context_list(context_hash))
|
30
|
+
end
|
31
|
+
alias :in_context :context
|
32
|
+
|
33
|
+
def context_list(context_hash)
|
34
|
+
return [] unless context_hash
|
35
|
+
return context_hash if context_hash.is_a?(Array)
|
36
|
+
context_hash.map { |key,value| "#{key}:#{value}" }
|
37
|
+
end
|
22
38
|
|
23
|
-
|
24
|
-
|
25
|
-
|
39
|
+
def sort!(order)
|
40
|
+
unless order && order.is_a?(Array)
|
41
|
+
raise('Array of uuids in order required')
|
42
|
+
end
|
43
|
+
uuids = order.map { |i| i[/([^\-]{32})$/, 1]}
|
44
|
+
uuids.each_with_index do |uuid, index|
|
45
|
+
if item = where(:uuid => uuid).first
|
46
|
+
# item.set(:position, index) # TODO: does not work in reality?
|
47
|
+
item.update_attribute(:position, index+1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
destroy_all(:conditions => {:uuid.nin => uuids})
|
51
|
+
end
|
26
52
|
end
|
27
53
|
|
54
|
+
private
|
55
|
+
|
28
56
|
def set_callname
|
29
|
-
self.callname
|
57
|
+
self.callname ||= label.parameterize
|
58
|
+
end
|
59
|
+
|
60
|
+
def cleanup_tags
|
61
|
+
self.tags.uniq!
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_position
|
65
|
+
return true if position
|
66
|
+
self.position = TagCategory.where(:context => context).count + 1
|
30
67
|
end
|
31
68
|
end
|
@@ -4,7 +4,8 @@ module Vidibus
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
field :tags_hash, :type => Hash
|
7
|
+
field :tags_hash, :type => Hash, :default => {}
|
8
|
+
before_save :save_category_tags
|
8
9
|
end
|
9
10
|
|
10
11
|
module ClassMethods
|
@@ -14,24 +15,46 @@ module Vidibus
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
categories
|
22
|
-
end
|
18
|
+
def tags
|
19
|
+
(tags_hash || {}).inject({}) do |categories, (key,tags)|
|
20
|
+
categories[key] = tags.join(self.class.tags_separator)
|
21
|
+
categories
|
23
22
|
end
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
def tags=(categories)
|
26
|
+
raise Error unless categories.is_a?(Hash)
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
hash = {}
|
29
|
+
@changed_category_tags ||= {}
|
30
|
+
categories.each do |category, tags|
|
31
|
+
category = category.to_s
|
32
|
+
tags = tags.split(self.class.tags_separator).map(&:strip).reject(&:blank?)
|
33
|
+
hash[category] = tags if tags.present?
|
34
|
+
if tags_hash[category] != tags
|
35
|
+
@changed_category_tags[category] = tags
|
32
36
|
end
|
33
|
-
self.tags_hash = tags_hash
|
34
37
|
end
|
38
|
+
self.tags_hash = hash
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Save all changed category tags.
|
44
|
+
def save_category_tags
|
45
|
+
return true unless @changed_category_tags
|
46
|
+
@changed_category_tags.each do |uuid, tags|
|
47
|
+
category = tag_category(uuid)
|
48
|
+
next unless category
|
49
|
+
category.tags += tags
|
50
|
+
category.save
|
51
|
+
end
|
52
|
+
@changed_category_tags = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# Find tag category by uuid.
|
56
|
+
def tag_category(uuid)
|
57
|
+
TagCategory.where(:uuid => uuid).first
|
35
58
|
end
|
36
59
|
end
|
37
60
|
end
|
metadata
CHANGED
@@ -1,147 +1,168 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-category_tag
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
- Martin Jagusch
|
7
|
+
authors:
|
8
|
+
- Martin Jagusch, Andre Pankratz
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: activesupport
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
version: "3.0"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
34
22
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: mongoid
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
40
33
|
none: false
|
41
|
-
requirements:
|
34
|
+
requirements:
|
42
35
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 2
|
47
|
-
- 0
|
48
|
-
version: "2.0"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
49
38
|
type: :runtime
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: vidibus-uuid
|
53
39
|
prerelease: false
|
54
|
-
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: vidibus-uuid
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
63
54
|
type: :runtime
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: rake
|
67
55
|
prerelease: false
|
68
|
-
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
77
70
|
type: :development
|
78
|
-
version_requirements: *id004
|
79
|
-
- !ruby/object:Gem::Dependency
|
80
|
-
name: rspec
|
81
71
|
prerelease: false
|
82
|
-
|
83
|
-
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
91
86
|
type: :development
|
92
|
-
version_requirements: *id005
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: factory_girl
|
95
87
|
prerelease: false
|
96
|
-
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: factory_girl
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
105
102
|
type: :development
|
106
|
-
version_requirements: *id006
|
107
|
-
- !ruby/object:Gem::Dependency
|
108
|
-
name: rcov
|
109
103
|
prerelease: false
|
110
|
-
|
111
|
-
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
119
118
|
type: :development
|
120
|
-
|
121
|
-
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
122
127
|
name: rdoc
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
123
135
|
prerelease: false
|
124
|
-
|
125
|
-
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: rr
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
133
150
|
type: :development
|
134
|
-
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
135
158
|
description: Tags organized in categories for Mongoid documents.
|
136
|
-
email:
|
159
|
+
email:
|
137
160
|
- async@mj.io
|
161
|
+
- andre@vidibus.com
|
138
162
|
executables: []
|
139
|
-
|
140
163
|
extensions: []
|
141
|
-
|
142
164
|
extra_rdoc_files: []
|
143
|
-
|
144
|
-
files:
|
165
|
+
files:
|
145
166
|
- lib/vidibus/category_tag/mongoid.rb
|
146
167
|
- lib/vidibus/category_tag/version.rb
|
147
168
|
- lib/vidibus/category_tag.rb
|
@@ -150,39 +171,34 @@ files:
|
|
150
171
|
- LICENSE
|
151
172
|
- README.md
|
152
173
|
- Rakefile
|
153
|
-
has_rdoc: true
|
154
174
|
homepage: https://github.com/vidibus/vidibus-category_tag
|
155
175
|
licenses: []
|
156
|
-
|
157
176
|
post_install_message:
|
158
177
|
rdoc_options: []
|
159
|
-
|
160
|
-
require_paths:
|
178
|
+
require_paths:
|
161
179
|
- lib
|
162
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
181
|
none: false
|
164
|
-
requirements:
|
165
|
-
- -
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
|
168
|
-
segments:
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
segments:
|
169
187
|
- 0
|
170
|
-
|
171
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
hash: 600532559351384376
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
190
|
none: false
|
173
|
-
requirements:
|
174
|
-
- -
|
175
|
-
- !ruby/object:Gem::Version
|
176
|
-
|
177
|
-
segments:
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
segments:
|
178
196
|
- 0
|
179
|
-
|
197
|
+
hash: 600532559351384376
|
180
198
|
requirements: []
|
181
|
-
|
182
199
|
rubyforge_project:
|
183
|
-
rubygems_version: 1.
|
200
|
+
rubygems_version: 1.8.24
|
184
201
|
signing_key:
|
185
202
|
specification_version: 3
|
186
203
|
summary: Tags organized in categories for Mongoid documents.
|
187
204
|
test_files: []
|
188
|
-
|