crowdint_acts-as-taggable-on 2.3.2 → 2.3.3
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/lib/acts-as-taggable-on/version.rb +1 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +3 -3
- data/lib/acts_as_taggable_on/tag.rb +6 -6
- data/lib/acts_as_taggable_on/tag_list.rb +4 -1
- data/lib/acts_as_taggable_on/tagger.rb +2 -1
- data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +3 -0
- metadata +3 -3
@@ -57,13 +57,13 @@ module ActsAsTaggableOn::Taggable
|
|
57
57
|
cache[owner] ||= ActsAsTaggableOn::TagList.new(*owner_tags_on(owner, context).map(&:name))
|
58
58
|
end
|
59
59
|
|
60
|
-
def set_owner_tag_list_on(owner, context,
|
60
|
+
def set_owner_tag_list_on(owner, context, tag_ids)
|
61
61
|
add_custom_context(context)
|
62
62
|
|
63
63
|
cache = cached_owned_tag_list_on(context)
|
64
64
|
cache.delete_if { |key, value| key.id == owner.id && key.class == owner.class }
|
65
65
|
|
66
|
-
cache[owner] = ActsAsTaggableOn::TagList.from(
|
66
|
+
cache[owner] = ActsAsTaggableOn::TagList.from(tag_ids)
|
67
67
|
end
|
68
68
|
|
69
69
|
def reload(*args)
|
@@ -79,7 +79,7 @@ module ActsAsTaggableOn::Taggable
|
|
79
79
|
cached_owned_tag_list_on(context).each do |owner, tag_list|
|
80
80
|
|
81
81
|
# Find existing tags or create non-existing tags:
|
82
|
-
tags = ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list.uniq)
|
82
|
+
tags = ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list.uniq, owner, context)
|
83
83
|
|
84
84
|
# Tag objects for owned tags
|
85
85
|
owned_tags = owner_tags_on(owner, context)
|
@@ -2,16 +2,16 @@ module ActsAsTaggableOn
|
|
2
2
|
class Tag < ::ActiveRecord::Base
|
3
3
|
include ActsAsTaggableOn::Utils
|
4
4
|
|
5
|
-
attr_accessible :name
|
5
|
+
attr_accessible :name, :tagger_id, :context
|
6
6
|
|
7
7
|
### ASSOCIATIONS:
|
8
8
|
|
9
9
|
has_many :taggings, :dependent => :destroy, :class_name => 'ActsAsTaggableOn::Tagging'
|
10
|
+
belongs_to :user
|
10
11
|
|
11
12
|
### VALIDATIONS:
|
12
13
|
|
13
14
|
validates_presence_of :name
|
14
|
-
validates_uniqueness_of :name
|
15
15
|
validates_length_of :name, :maximum => 255
|
16
16
|
|
17
17
|
### SCOPES:
|
@@ -20,8 +20,8 @@ module ActsAsTaggableOn
|
|
20
20
|
where(["lower(name) = ?", name.downcase])
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.named_any(list)
|
24
|
-
where(list.map { |tag| sanitize_sql(["lower(name) = ?", tag.to_s.downcase]) }.join(" OR "))
|
23
|
+
def self.named_any(list, owner, context)
|
24
|
+
where(list.map { |tag| sanitize_sql(["lower(name) = ? and tagger_id = ? and context = ?", tag.to_s.downcase, owner, context]) }.join(" OR "))
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.named_like(name)
|
@@ -38,12 +38,12 @@ module ActsAsTaggableOn
|
|
38
38
|
named_like(name).first || create(:name => name)
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.find_or_create_all_with_like_by_name(*list)
|
41
|
+
def self.find_or_create_all_with_like_by_name(*list, owner, context)
|
42
42
|
list = [list].flatten
|
43
43
|
|
44
44
|
return [] if list.empty?
|
45
45
|
|
46
|
-
existing_tags = Tag.named_any(list).all
|
46
|
+
existing_tags = Tag.named_any(list, owner, context).all
|
47
47
|
new_tag_names = list.reject do |name|
|
48
48
|
name = comparable_name(name)
|
49
49
|
existing_tags.any? { |tag| comparable_name(tag.name) == name }
|
@@ -14,7 +14,10 @@ module ActsAsTaggableOn
|
|
14
14
|
# Example:
|
15
15
|
# tag_list = TagList.from("One , Two, Three")
|
16
16
|
# tag_list # ["One", "Two", "Three"]
|
17
|
-
def self.from(
|
17
|
+
def self.from(tag_ids)
|
18
|
+
|
19
|
+
string = ActsAsTaggableOn::Tag.find(tag_ids)
|
20
|
+
string = string.respond_to?(:map) ? string.map(&:name) : string.name
|
18
21
|
string = string.join(ActsAsTaggableOn.glue) if string.respond_to?(:join)
|
19
22
|
|
20
23
|
new.tap do |tag_list|
|
@@ -15,9 +15,10 @@ module ActsAsTaggableOn
|
|
15
15
|
# end
|
16
16
|
def acts_as_tagger(opts={})
|
17
17
|
class_eval do
|
18
|
+
|
18
19
|
has_many :owned_taggings, opts.merge(:as => :tagger, :dependent => :destroy,
|
19
20
|
:include => :tag, :class_name => "ActsAsTaggableOn::Tagging")
|
20
|
-
has_many :owned_tags, :
|
21
|
+
has_many :owned_tags, :class_name => "ActsAsTaggableOn::Tag" , :as => :tagger
|
21
22
|
end
|
22
23
|
|
23
24
|
include ActsAsTaggableOn::Tagger::InstanceMethods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowdint_acts-as-taggable-on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: '0'
|
207
207
|
segments:
|
208
208
|
- 0
|
209
|
-
hash:
|
209
|
+
hash: 3126823082438894058
|
210
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
211
|
none: false
|
212
212
|
requirements:
|
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
segments:
|
217
217
|
- 0
|
218
|
-
hash:
|
218
|
+
hash: 3126823082438894058
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
221
|
rubygems_version: 1.8.23
|