lean_tag 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 826bf0e70d6602d1652e50075eebb8cdc7a6954a
4
- data.tar.gz: 1582db1e1b197c7aba0f15f3a87d67fdd4e240d0
3
+ metadata.gz: 2ffdb5ec65f889d90046f2628c41fe0dd9ca59f4
4
+ data.tar.gz: 31319030ef5e90fc62f6e298617c8fb2e29b4953
5
5
  SHA512:
6
- metadata.gz: ff3b6bd7dbc748e48cebdbd4cbbecff204581cbe0f3fa9be61d6e2e25a2f220c8e220e7f77c63dfedab1615541940c3fa44874fca04365a9c2aca2f19a56f908
7
- data.tar.gz: 2ca680df07bc3377d291be9c0903b60b83ae2bef91bbda84257478c86c992c4e3f23194fe46ba9f7dc047625f502712b5e14018761b81a30ec9a0da7d43e9eee
6
+ metadata.gz: d1c26a81cd07972b6814d7b6a7c630c816743eb30af43e7df9942058deb6c05a8364170fe8cea17c3c3079a398234ab7c285b9e62287d9b4b83a3eab298c4d8c
7
+ data.tar.gz: 4f461ede0df0fcba085aaa3bee431b7a5c289beae1b53b1f6e25123c10cd0bd0b569943721814e8d8e172bd467b1f615d0b740288b9466d83593abbcf4bc075f
@@ -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, method='mark_for_destruction')
76
- tag = self.find_tag(tag) if tag.is_a?(String)
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
- destroy_if_unused(tag)
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.find_tag(tag) if tag.is_a?(String)
73
+ tag = self.tags.where(name: tag).first if tag.is_a?(String)
88
74
 
89
- tagging = tagging.find_by_tag_id(tag.id)
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
- tag_names = value.blank? ? [] : value.split(LeanTag.config.delimiter)
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(LeanTag.config.delimiter)
100
+ self.tags.map(&:name).join(',')
111
101
  end
112
102
 
113
103
  end
@@ -1,5 +1,5 @@
1
1
  module LeanTag
2
2
 
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lean_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Ellis