lean_tag 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.
- checksums.yaml +4 -4
- data/lib/lean_tag/taggable.rb +16 -26
- data/lib/lean_tag/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ffdb5ec65f889d90046f2628c41fe0dd9ca59f4
|
4
|
+
data.tar.gz: 31319030ef5e90fc62f6e298617c8fb2e29b4953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c26a81cd07972b6814d7b6a7c630c816743eb30af43e7df9942058deb6c05a8364170fe8cea17c3c3079a398234ab7c285b9e62287d9b4b83a3eab298c4d8c
|
7
|
+
data.tar.gz: 4f461ede0df0fcba085aaa3bee431b7a5c289beae1b53b1f6e25123c10cd0bd0b569943721814e8d8e172bd467b1f615d0b740288b9466d83593abbcf4bc075f
|
data/lib/lean_tag/taggable.rb
CHANGED
@@ -6,6 +6,8 @@ module LeanTag
|
|
6
6
|
has_many :taggings, class_name: "LeanTag::Tagging", as: :record, inverse_of: :record, dependent: :destroy
|
7
7
|
has_many :tags, through: :taggings
|
8
8
|
|
9
|
+
accepts_nested_attributes_for :taggings, allow_destroy: true
|
10
|
+
|
9
11
|
scope :with_tags, -> { includes(:tags) }
|
10
12
|
end
|
11
13
|
end
|
@@ -44,26 +46,12 @@ module LeanTag
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
##
|
48
|
-
# Destroy a tag if it's no longer in use
|
49
|
-
def destroy_if_unused(tag)
|
50
|
-
if tag.taggings_count && LeanTag.config.remove_unused
|
51
|
-
tag.destroy
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
49
|
##
|
56
50
|
# Finds current tags on this record which aren't in the passed list
|
57
51
|
def excluded_tags(tag_names)
|
58
52
|
self.tags.reject { |t| t.name.in?(tag_names) }
|
59
53
|
end
|
60
54
|
|
61
|
-
##
|
62
|
-
# Finds a tag on this record by name
|
63
|
-
def find_tag(tag_name)
|
64
|
-
self.tags.find_by_name(tag_name)
|
65
|
-
end
|
66
|
-
|
67
55
|
##
|
68
56
|
# Finds current tags on this record which are in the passed list
|
69
57
|
def included_tags(tag_names)
|
@@ -72,30 +60,32 @@ module LeanTag
|
|
72
60
|
|
73
61
|
##
|
74
62
|
# Removes a single tag on parent save
|
75
|
-
def remove_tag(tag
|
76
|
-
tag = self.
|
77
|
-
|
78
|
-
tagging = tagging.find_by_tag_id(tag.id)
|
79
|
-
tagging.send(method) unless tagging.nil?
|
63
|
+
def remove_tag(tag)
|
64
|
+
tag = self.tags.where(name: tag).first if tag.is_a?(String)
|
80
65
|
|
81
|
-
|
66
|
+
tagging = self.taggings.where(tag_id: tag.id).first
|
67
|
+
tagging.mark_for_destruction unless tagging.nil?
|
82
68
|
end
|
83
69
|
|
84
70
|
##
|
85
71
|
# Removes a single tag immediately
|
86
72
|
def remove_tag!(tag)
|
87
|
-
tag = self.
|
73
|
+
tag = self.tags.where(name: tag).first if tag.is_a?(String)
|
88
74
|
|
89
|
-
tagging =
|
75
|
+
tagging = self.taggings.where(tag_id: tag.id).first
|
90
76
|
tagging.destroy unless tagging.nil?
|
91
|
-
|
92
|
-
destroy_if_unused(tag)
|
93
77
|
end
|
94
78
|
|
95
79
|
##
|
96
80
|
# Set a list of tags
|
97
81
|
def tag_list=(value)
|
98
|
-
|
82
|
+
if value.is_a?(String)
|
83
|
+
tag_names = value.split(LeanTag.config.delimiter)
|
84
|
+
elsif value.is_a?(Array)
|
85
|
+
tag_names = value
|
86
|
+
else
|
87
|
+
tag_names = []
|
88
|
+
end
|
99
89
|
|
100
90
|
# Get rid of existing tags that aren't in the list
|
101
91
|
self.excluded_tags(tag_names).each { |t| self.remove_tag(t) }
|
@@ -107,7 +97,7 @@ module LeanTag
|
|
107
97
|
##
|
108
98
|
# Returns a delimited list of tag names
|
109
99
|
def tag_list
|
110
|
-
self.tags.map(&:name).join(
|
100
|
+
self.tags.map(&:name).join(',')
|
111
101
|
end
|
112
102
|
|
113
103
|
end
|
data/lib/lean_tag/version.rb
CHANGED