lean_tag 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/2_create_taggings.rb +2 -0
- data/lib/lean_tag/tag.rb +6 -1
- data/lib/lean_tag/taggable.rb +3 -3
- data/lib/lean_tag/tagging.rb +2 -0
- data/lib/lean_tag/version.rb +1 -1
- data/lib/lean_tag.rb +8 -3
- 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: ba1148a5843581c8b6844c785e2d2872dbcee660
|
4
|
+
data.tar.gz: 4ff68b54986e62f5cec4ea936ae2e3f0425a06c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e5f3baa9842ee5b80e0af719ceb54fb1f75ef969650aae50a6b1554aaaa5b1405d1ad68dca1d007d36dcb819120d63b3b85a2f7149115a3793534d2fa4a44c
|
7
|
+
data.tar.gz: 9d1bfa8bf83d34d4887fb3a886bfd8b66968a0c4242108e282ef72eb1c96b5fccde47442142356b56aca1fdef3360c5f45ff48f1bdc280ab52652c270d2a1d2a
|
data/lib/lean_tag/tag.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module LeanTag
|
2
2
|
class Tag < ActiveRecord::Base
|
3
3
|
|
4
|
+
self.table_name = :tags
|
5
|
+
|
4
6
|
has_many :records, through: :taggings
|
5
7
|
has_many :taggings, class_name: "LeanTag::Tagging", inverse_of: :tag, counter_cache: true
|
6
8
|
|
@@ -9,7 +11,10 @@ module LeanTag
|
|
9
11
|
validates :name, presence: true, uniqueness: true
|
10
12
|
|
11
13
|
def name=(value)
|
12
|
-
|
14
|
+
if value.present?
|
15
|
+
self[:name] = value.gsub(/[^0-9a-zA-Z]+/, "")
|
16
|
+
self[:name] = self[:name].downcase if LeanTag.config.force_lowercase
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
end
|
data/lib/lean_tag/taggable.rb
CHANGED
@@ -49,7 +49,7 @@ module LeanTag
|
|
49
49
|
##
|
50
50
|
# Destroy a tag if it's no longer in use
|
51
51
|
def destroy_if_unused(tag)
|
52
|
-
if tag.taggings_count && LeanTag.remove_unused
|
52
|
+
if tag.taggings_count && LeanTag.config.remove_unused
|
53
53
|
tag.destroy
|
54
54
|
end
|
55
55
|
end
|
@@ -97,7 +97,7 @@ module LeanTag
|
|
97
97
|
##
|
98
98
|
# Set a list of tags
|
99
99
|
def tag_list=(value)
|
100
|
-
tag_names = value.blank? ? [] : value.split(LeanTag.delimiter)
|
100
|
+
tag_names = value.blank? ? [] : value.split(LeanTag.config.delimiter)
|
101
101
|
|
102
102
|
# Get rid of existing tags that aren't in the list
|
103
103
|
self.excluded_tags(tag_names).each { |t| self.remove_tag(t) }
|
@@ -109,7 +109,7 @@ module LeanTag
|
|
109
109
|
##
|
110
110
|
# Returns a delimited list of tag names
|
111
111
|
def tag_list
|
112
|
-
self.tags.map(&:name).join(LeanTag.delimiter)
|
112
|
+
self.tags.map(&:name).join(LeanTag.config.delimiter)
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
data/lib/lean_tag/tagging.rb
CHANGED
data/lib/lean_tag/version.rb
CHANGED
data/lib/lean_tag.rb
CHANGED
@@ -6,14 +6,19 @@ require_relative 'lean_tag/engine' if defined?(Rails)
|
|
6
6
|
|
7
7
|
module LeanTag
|
8
8
|
|
9
|
-
def self.
|
9
|
+
def self.config
|
10
10
|
@configuration ||= Configuration.new
|
11
|
-
yield @configuration if block_given?
|
12
11
|
end
|
13
12
|
|
13
|
+
def self.setup
|
14
|
+
self.config
|
15
|
+
yield self.config if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
|
14
19
|
class Configuration
|
15
20
|
|
16
|
-
attr_accessor :delimiter, :force_lowercase, :
|
21
|
+
attr_accessor :delimiter, :force_lowercase, :remove_unused
|
17
22
|
|
18
23
|
def initialize
|
19
24
|
self.delimiter = ','
|