gutentag 1.0.0 → 1.1.0

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: e38980a4454dabe309f3c203ddd7b918f82c5193
4
- data.tar.gz: 8b50af89daa6b099ae1cca584478758d11ab6b0c
3
+ metadata.gz: a26cb66caf12d398610c04fd395478ad28b1274d
4
+ data.tar.gz: 14ee875c010f87bb3f2fafe5e4bc4076210ae7a8
5
5
  SHA512:
6
- metadata.gz: 31686ed82181198d188ea9e6f323b3e47e9dbb69e53d9458a2d1adbcbd75d17cc2baf6a563428caabe9dcca0552c22b1efb785e5834312baadefa59f2eeb9a4c
7
- data.tar.gz: d9c469b2df3bc48d991700f0e062aa626efeca3c2d15fd813f0f108705ad471d4d833814fbf61af29d577a276e1936cc418746c8e37ce19e448bbfd12a51978c
6
+ metadata.gz: 8b6c6f02542b419644cdc30e07d776227a98aef5479528d7aa80be05fa45757fc7f6eaeacd298a64df20d72cae62b63bd9e3846d1e460a13a871faabe8c9007a
7
+ data.tar.gz: 6d58adf70948425b4dacb24284392bbd9faf8b84c5108fffb15b042e2edd0277cfb77d78675c4c23aefa624dc3d7e401405862534d8d6f8ab34d160c8c62ce58
data/README.md CHANGED
@@ -13,6 +13,7 @@ This was built partly as a proof-of-concept, and partly to see how a tagging gem
13
13
  * [Usage](#usage)
14
14
  * [Installation](#installation)
15
15
  * [Upgrading](#upgrading)
16
+ * [Configuration](#configuration)
16
17
  * [Contribution](#contribution)
17
18
  * [Licence](#licence)
18
19
 
@@ -68,7 +69,7 @@ Article.tagged_with(:ids => [tag_a.id, tag_b.id], :match => :all)
68
69
  Get it into your Gemfile - and don't forget the version constraint!
69
70
 
70
71
  ```Ruby
71
- gem 'gutentag', '~> 1.0.0'
72
+ gem 'gutentag', '~> 1.1.0'
72
73
  ```
73
74
 
74
75
  Next: your tags get persisted to your database, so let's import and run the migrations to get the tables set up:
@@ -105,6 +106,12 @@ add_index :gutentag_tags, :taggings_count
105
106
 
106
107
  <h2 id="upgrading">Upgrading</h2>
107
108
 
109
+ ### 1.1.0
110
+
111
+ No breaking changes.
112
+
113
+ Thanks to [Robin](https://github.com/rmehner), Gutentag::Tag#name will now validate default database column lengths ([#41](https://github.com/pat/gutentag/pull/41)).
114
+
108
115
  ### 1.0.0
109
116
 
110
117
  Behaviour that was deprecated in 0.9.0 (`has_many_tags`, `tagged_with` arguments) have now been removed.
@@ -139,6 +146,40 @@ rename_table :tags, :gutentag_tags
139
146
  rename_table :taggings, :gutentag_taggings
140
147
  ```
141
148
 
149
+ <h2 id="configuration">Configuration</h2>
150
+
151
+ Gutentag tries to take a convention-over-configuration approach, while also striving to be modular enough to allow changes to behaviour in certain cases.
152
+
153
+ ### Tag validations
154
+
155
+ The default validations on `Gutentag::Tag` are:
156
+
157
+ * presence of the tag name.
158
+ * case-insensitive uniqueness of the tag name.
159
+ * maximum length of the tag name (if the column has a limit).
160
+
161
+ You can view the logic for this in [`Gutentag::TagValidations`](lib/gutentag/tag_validations.rb), and you can set an alternative if you wish:
162
+
163
+ ```ruby
164
+ Gutentag.tag_validations = CustomTagValidations
165
+ ```
166
+
167
+ The supplied value must respond to `call`, and the argument supplied is the model.
168
+
169
+ ### Tag normalisation
170
+
171
+ Tag normalisation is used to convert supplied tag values consistently into string tag names. [The default](lib/gutentag.rb#L15) is to convert the value into a string, and then to lower-case.
172
+
173
+ If you want to do something different, provide an object that responds to call and accepts a single value to `Gutentag.normaliser`:
174
+
175
+ ```ruby
176
+ Gutentag.normaliser = lambda { |value| value.to_s.upcase }
177
+ ```
178
+
179
+ ### Case-sensitive tags
180
+
181
+ Gutentag ignores case by default, but can be customised to be case-sensitive by supplying your own validations and normaliser, as outlined by [Robin Mehner](https://github.com/rmehner) in [issue 42](https://github.com/pat/gutentag/issues/42). Further changes may be required for your schema though, depending on your database.
182
+
142
183
  <h2 id="contribution">Contribution</h2>
143
184
 
144
185
  Please note that this project now has a [Contributor Code of Conduct](http://contributor-covenant.org/version/1/0/0/). By participating in this project you agree to abide by its terms.
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "gutentag"
6
- s.version = "1.0.0"
6
+ s.version = "1.1.0"
7
7
  s.authors = ["Pat Allan"]
8
8
  s.email = ["pat@freelancing-gods.com"]
9
9
  s.homepage = "https://github.com/pat/gutentag"
@@ -13,6 +13,9 @@ class Gutentag::TagValidations
13
13
  klass.validates :name,
14
14
  :presence => true,
15
15
  :uniqueness => {:case_sensitive => false}
16
+
17
+ limit = klass.columns_hash["name"].limit
18
+ klass.validates_length_of :name, :maximum => limit if limit.present?
16
19
  end
17
20
 
18
21
  private
@@ -63,5 +63,22 @@ describe Gutentag::Tag, :type => :model do
63
63
  tag = Gutentag::Tag.create(:name => "Pancakes")
64
64
  expect(tag.errors[:name].length).to eq(1)
65
65
  end
66
+
67
+ if ENV["DATABASE"] == "mysql" || (
68
+ Gem::Version.new(Rails.version) < Gem::Version.new("4.2.0")
69
+ )
70
+ # When using MySQL or Rails before 4.2, string columns convert to
71
+ # VARCHAR(255), therefore the column has a limit of 255, even though we
72
+ # did not specify a limit
73
+ it "validates the length of the name" do
74
+ tag = Gutentag::Tag.create(:name => "a" * 256)
75
+ expect(tag.errors[:name].length).to eq(1)
76
+ end
77
+ else
78
+ it "does not validate the length if the column has no limit" do
79
+ tag = Gutentag::Tag.create(:name => "a" * 256)
80
+ expect(tag.errors[:name].length).to eq(0)
81
+ end
82
+ end
66
83
  end
67
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gutentag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-29 00:00:00.000000000 Z
11
+ date: 2017-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.6.13
177
+ rubygems_version: 2.6.14
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Good Tags