lean_tag 1.0.5 → 1.0.6

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: f369a5cfbafb5c23c6842f54d5d4559fa7f66569
4
- data.tar.gz: 8f603c5cd549aaae3d8fe1b6cd955eb1c48341ec
3
+ metadata.gz: 8ca52f15d56e66b8a54ceb0c32b770fe71236dd6
4
+ data.tar.gz: 836cfdec108219024dd45764f3988579a39f1b37
5
5
  SHA512:
6
- metadata.gz: f765bdb09d95df190fddc8c54c12bf074368f24ad7ac10ced9338a6e6896c25eea9a04629d01fed5d0606c41248511afd0cd72e2bf2673f726c278926cfe9749
7
- data.tar.gz: 4129c3c05ba79ee0d85faad922d520cffcbe7a51d31d1f924c16212bb04c4c15f8fdaa4ed1eb00d6906b0b88dda9ab2090fc152cd269f8b3c9fd4ab6c3599620
6
+ metadata.gz: acc268c6caf08fbc494c232c268f4634c436dca828b9f393e28168e18ad31c826057a31af00fd8ca3c0b328a5f9084887857258e0fa1f0df3e72339338a0bfb3
7
+ data.tar.gz: 6a95536c112c1cc66aa9143a09c3f2a1d3ca356d4e5026b988a4ff037a1b3cfcb18eb95baf457786993018a3f9e1b05a668688e03ab1562c6336da1b51f1c5a1
@@ -5,7 +5,6 @@ require 'active_support/core_ext/module'
5
5
  require_relative 'lean_tag/engine' if defined?(Rails)
6
6
 
7
7
  module LeanTag
8
-
9
8
  def self.config
10
9
  @configuration ||= Configuration.new
11
10
  end
@@ -15,18 +14,13 @@ module LeanTag
15
14
  yield self.config if block_given?
16
15
  end
17
16
 
18
-
19
17
  class Configuration
20
-
21
- attr_accessor :delimiter, :force_lowercase, :legal_characters, :remove_unused
18
+ attr_accessor :delimiter, :force_lowercase, :remove_unused
22
19
 
23
20
  def initialize
24
21
  self.delimiter = ','
25
22
  self.force_lowercase = true
26
- self.legal_characters = /[^0-9a-zA-Z]+/
27
23
  self.remove_unused = true
28
24
  end
29
-
30
25
  end
31
-
32
26
  end
@@ -6,8 +6,6 @@ require 'lean_tag/tagging'
6
6
 
7
7
  module LeanTag
8
8
  class Engine < ::Rails::Engine
9
-
10
9
  isolate_namespace LeanTag
11
-
12
10
  end
13
11
  end
@@ -1,6 +1,5 @@
1
1
  module LeanTag
2
2
  class Tag < ActiveRecord::Base
3
-
4
3
  self.table_name = :tags
5
4
 
6
5
  has_many :records, through: :taggings
@@ -13,10 +12,9 @@ module LeanTag
13
12
 
14
13
  def name=(value)
15
14
  if value.present?
16
- self[:name] = value.gsub(LeanTag.config.legal_characters, "")
15
+ self[:name] = value.gsub(/[^0-9a-zA-Z]+/, "")
17
16
  self[:name] = self[:name].downcase if LeanTag.config.force_lowercase
18
17
  end
19
18
  end
20
-
21
19
  end
22
20
  end
@@ -1,8 +1,6 @@
1
1
  module LeanTag
2
2
  module Taggable
3
-
4
3
  def self.extended(base)
5
-
6
4
  def taggable_on(relation="tags")
7
5
  extend ClassMethods
8
6
 
@@ -20,16 +18,13 @@ module LeanTag
20
18
  define_method "add_#{tag_relation.to_s.singularize}!", ->(tag) { _add_tag!(tag, tag_relation) }
21
19
  define_method "#{tag_relation.to_s.singularize}_list", ->() { _get_tag_list(tag_relation) }
22
20
  define_method "remove_#{tag_relation.to_s.singularize}", ->(tag) { _remove_tag(tag, tag_relation) }
23
- define_method "remove_#{tag_relation.to_s.singularize}!", ->(tag) { _remove_tag(tag, tag_relation) }
21
+ define_method "remove_#{tag_relation.to_s.singularize}!", ->(tag) { _remove_tag!(tag, tag_relation) }
24
22
  define_method "#{tag_relation.to_s.singularize}_list=", ->(list) { _set_tag_list(list, tag_relation) }
25
23
  end
26
24
  end
27
-
28
25
  end
29
26
 
30
-
31
27
  module ClassMethods
32
-
33
28
  ##
34
29
  # Returns all records which include at least one of the passed tags
35
30
  def tagged_with(list, filter="tags")
@@ -39,27 +34,25 @@ module LeanTag
39
34
  return self.where(id: taggings.select(:record_id).distinct)
40
35
  end
41
36
 
42
-
43
37
  ##
44
38
  # Get all tags used by this class
45
39
  def tags(filter="tags")
46
40
  taggings = Tagging.where(record_type: self.name, filter: filter).where(filter: filter)
47
41
  return Tag.where(id: taggings.select(:tag_id).distinct)
48
42
  end
49
-
50
43
  end
51
44
 
52
-
53
45
  module InstanceMethods
54
-
55
46
  ##
56
47
  # Adds a single tag on parent save
57
48
  def _add_tag(tag, filter="tags")
58
49
  if tag.is_a?(String)
59
- record = Tag.find_or_create_by(name: tag)
50
+ record = Tag.find_by_name(tag)
60
51
  end
61
52
 
62
- unless self._taggings(filter).exists?(tag_id: record.id)
53
+ if record.nil?
54
+ self._tags(filter).build(name: tag)
55
+ elsif !self._taggings(filter).exists?(tag_id: record.id)
63
56
  self._taggings(filter).build(tag_id: record.id)
64
57
  end
65
58
  end
@@ -104,9 +97,8 @@ module LeanTag
104
97
  tag_names = []
105
98
  end
106
99
 
107
- tags = self._taggings(filter).map(&:tag)
108
- tags.reject! { |t| t.name.in?(tag_names) }
109
- tags.each { |t| self._remove_tag(t, filter) }
100
+ tags = Tag.where(id: self._taggings(filter).select(:tag_id).distinct)
101
+ tags.reject { |t| t.name.in?(tag_names) }.each { |t| self._remove_tag(t, filter) }
110
102
 
111
103
  # Add any new tags
112
104
  tag_names.each { |t| self._add_tag(t, filter) }
@@ -123,8 +115,6 @@ module LeanTag
123
115
  def _taggings(filter)
124
116
  self.send("#{filter}_taggings")
125
117
  end
126
-
127
118
  end
128
-
129
119
  end
130
120
  end
@@ -1,6 +1,5 @@
1
1
  module LeanTag
2
2
  class Tagging < ActiveRecord::Base
3
-
4
3
  self.table_name = :taggings
5
4
 
6
5
  belongs_to :record, polymorphic: true, inverse_of: :taggings
@@ -8,8 +7,8 @@ module LeanTag
8
7
 
9
8
  scope :for, -> (filter) { where(filter: filter) }
10
9
 
10
+ validates :record_id, presence: true
11
11
  validates :record_type, presence: true
12
12
  validates :tag, presence: true, uniqueness: { scope: [:record_type, :record_id] }
13
-
14
13
  end
15
14
  end
@@ -1,5 +1,3 @@
1
1
  module LeanTag
2
-
3
- VERSION = '1.0.5'
4
-
2
+ VERSION = '1.0.6'
5
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lean_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Ellis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.4.4
106
+ rubygems_version: 2.6.14
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A lightweight method for tagging content