lean_tag 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5cf556a9c2a9df241b42def112546eae8296a4c
4
- data.tar.gz: 7d543b45c7596ec547f85715f340a21da152d353
3
+ metadata.gz: ba1148a5843581c8b6844c785e2d2872dbcee660
4
+ data.tar.gz: 4ff68b54986e62f5cec4ea936ae2e3f0425a06c7
5
5
  SHA512:
6
- metadata.gz: c357fffbd13651a7cde6121681f3a936faff15ac155a25e6522da539278c8908892208ceb32da8e78de6cf2d72a48706cacbe99852befdd7a73f6afeac9b5148
7
- data.tar.gz: 7a2fed477fb443be8e657cb652c831487b5812034f086ddb79cdc2a66ce4e78198e547412337a08aa1e5c8fbd9112c3438e9ec9ce47075ef1121a351236e251a
6
+ metadata.gz: 93e5f3baa9842ee5b80e0af719ceb54fb1f75ef969650aae50a6b1554aaaa5b1405d1ad68dca1d007d36dcb819120d63b3b85a2f7149115a3793534d2fa4a44c
7
+ data.tar.gz: 9d1bfa8bf83d34d4887fb3a886bfd8b66968a0c4242108e282ef72eb1c96b5fccde47442142356b56aca1fdef3360c5f45ff48f1bdc280ab52652c270d2a1d2a
@@ -6,5 +6,7 @@ class CreateTaggings < ActiveRecord::Migration
6
6
 
7
7
  t.timestamps null: false
8
8
  end
9
+
10
+ add_index [:record_type, :record_id, :filter]
9
11
  end
10
12
  end
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
- self[:name] = value.present? ? value.gsub(/[^0-9a-zA-Z]+/, "").downcase : nil
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
@@ -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
@@ -1,6 +1,8 @@
1
1
  module LeanTag
2
2
  class Tagging < ActiveRecord::Base
3
3
 
4
+ self.table_name = :taggings
5
+
4
6
  belongs_to :record, polymorphic: true, inverse_of: :taggings
5
7
  belongs_to :tag, class_name: "LeanTag::Tag", inverse_of: :taggings
6
8
 
@@ -1,5 +1,5 @@
1
1
  module LeanTag
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  end
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.setup
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, :force_parameterize
21
+ attr_accessor :delimiter, :force_lowercase, :remove_unused
17
22
 
18
23
  def initialize
19
24
  self.delimiter = ','
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Ellis