permalink 2.1.0 → 3.0.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
  SHA256:
3
- metadata.gz: b59f20670f6bcfbd6b204ad5e23aefcce7abf477b6b574d165d87e892e9b6afc
4
- data.tar.gz: dfdee1e9df89d3d11e9d9240811c00a4307abf1a22accc6346e992b092326225
3
+ metadata.gz: 2ba3402f7ea2dc013ff8162130c6cb1753d382eb3cbf875a862a5d70b695434a
4
+ data.tar.gz: 0b03c85505106a762905f31437ea052f1278d7bb559755eda3e5ca1f7eccb00b
5
5
  SHA512:
6
- metadata.gz: 79d9f75edc2fd001ffe2cc4544ba5bd0fbc38a7a842641f5d656136961233aa926a72e9ad2e5d387641e354d5b4dd919f92567289d84a137644ed7edab782857
7
- data.tar.gz: '080cb2da608b09403a9e4aae8d42f1465a0cb33b3902aadf2f4747c50c72bd21bd361f91dc1abce55503df7d5488d5332099e20cc9755938ae54f8a5045cd9a3'
6
+ metadata.gz: 6f4fb178b99a2884e48c4a08b8e3e6f287eb5072626305aebb0aaf42cacd77945e6b007139a7320a4ff02dea046d2ce7dda5d7ff62205301cf0e37c04525fc64
7
+ data.tar.gz: 0e40038144ba10a2a757f3cc2684d336b79a9f508a159747071cb27690d69e18aa16a6e67672c51dbabdebd16a53e4f9963ff41a4ee399f97ff844c718a527e9
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: test
3
+
4
+ on:
5
+ pull_request_target:
6
+ push:
7
+ branches:
8
+ - main
9
+ workflow_dispatch:
10
+ inputs: {}
11
+
12
+ jobs:
13
+ test:
14
+ name: test
15
+ runs-on: "ubuntu-latest"
16
+ if: |
17
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
18
+ github.actor != 'dependabot[bot]'
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby: ["3.2", "3.3"]
23
+
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+
27
+ - uses: actions/cache@v4
28
+ with:
29
+ path: vendor/bundle
30
+ key: >
31
+ ${{ runner.os }}-${{ matrix.ruby }}-gems
32
+
33
+ - name: Set up Ruby
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+
38
+ - name: Install Ruby dependencies
39
+ run: |
40
+ bundle install
41
+
42
+ - name: Run tests
43
+ run: |
44
+ bundle exec rake
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.2
7
7
  NewCops: enable
8
8
 
9
9
  Metrics/MethodLength:
@@ -11,3 +11,6 @@ Metrics/MethodLength:
11
11
 
12
12
  Metrics/ClassLength:
13
13
  Enabled: false
14
+
15
+ Minitest/EmptyLineBeforeAssertionMethods:
16
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ <!--
4
+ Prefix your message with one of the following:
5
+
6
+ - [Added] for new features.
7
+ - [Changed] for changes in existing functionality.
8
+ - [Deprecated] for soon-to-be removed features.
9
+ - [Removed] for now removed features.
10
+ - [Fixed] for any bug fixes.
11
+ - [Security] in case of vulnerabilities.
12
+ -->
13
+
14
+ ## 3.0.0 - Apr 22, 2024
15
+
16
+ - [Changed] Plugin is not activated globally by default anymore; add
17
+ `Permalink.active_record` to your model or `ApplicationRecord`.
18
+ - [Changed] Required ruby version is now 3.2 or newer.
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2011-2024 Nando Vieira, released under the MIT license
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Permalink
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/fnando/permalink.svg)](https://codeclimate.com/github/fnando/permalink)
4
- [![Build Status](https://travis-ci.org/fnando/permalink.svg)](https://travis-ci.org/fnando/permalink)
3
+ [![test](https://github.com/fnando/permalink/actions/workflows/test.yml/badge.svg)](https://github.com/fnando/permalink/actions/workflows/test.yml)
5
4
  [![Gem](https://img.shields.io/gem/v/permalink.svg)](https://rubygems.org/gems/permalink)
6
5
  [![Gem](https://img.shields.io/gem/dt/permalink.svg)](https://rubygems.org/gems/permalink)
7
6
 
@@ -11,11 +10,24 @@
11
10
 
12
11
  ## Usage
13
12
 
13
+ > [!NOTE]
14
+ >
15
+ > To have the method `permalink` available, you need to inject
16
+ > `Permalink.active_record` on each model, or use something like your
17
+ > `ApplicationModel`.
18
+
19
+ ```ruby
20
+ class ApplicationRecord < ActiveRecord::Base
21
+ primary_abstract_class
22
+ include Permalink.active_record
23
+ end
24
+ ```
25
+
14
26
  Add the method call `permalink` to your model. Your model should have a
15
27
  `permalink` attribute.
16
28
 
17
29
  ```ruby
18
- class Page < ActiveRecord::Base
30
+ class Page < ApplicationRecord
19
31
  permalink :title
20
32
  end
21
33
  ```
@@ -23,14 +35,13 @@ end
23
35
  You can specify the permalink field:
24
36
 
25
37
  ```ruby
26
- class page < ActiveRecord::Base
38
+ class Page < ApplicationRecord
27
39
  permalink :title, to: "title_permalink"
28
40
  end
29
41
  ```
30
42
 
31
- If you don't want to use `permalink`, you can call
32
- `Permalink.generate("some text")` string method and manage the permalink process
33
- by yourself.
43
+ If you don't want to use `permalink`, you can call `Permalink.call("some text")`
44
+ string method and manage the permalink process by yourself.
34
45
 
35
46
  Permalinks are not unique by default. `permalink` overrides `to_param` as
36
47
  following:
@@ -44,7 +55,7 @@ end
44
55
  You can define the `to_param` format:
45
56
 
46
57
  ```ruby
47
- class Page < ActiveRecord::Base
58
+ class Page < ApplicationRecord
48
59
  permalink :title, to_param: %w(id permalink page)
49
60
  end
50
61
  ```
@@ -56,7 +67,7 @@ routes.
56
67
  If you want to generate unique permalink, use the `:unique` option:
57
68
 
58
69
  ```ruby
59
- class Page < ActiveRecord::Base
70
+ class Page < ApplicationRecord
60
71
  permalink :title, unique: true, to_param: "permalink"
61
72
  end
62
73
  ```
@@ -65,7 +76,7 @@ The permalink can be tied to a given scope. Let's say you want to have unique
65
76
  permalinks by user. Just set the `:scope` option.
66
77
 
67
78
  ```ruby
68
- class Page < ActiveRecord::Base
79
+ class Page < ApplicationRecord
69
80
  belongs_to :user
70
81
  permalink :title, unique: true, scope: "user_id"
71
82
  end
@@ -91,14 +102,14 @@ evaluated and the instance has no permalink set.
91
102
  You can force the permalink generation by setting the `:force` option.
92
103
 
93
104
  ```ruby
94
- class Page < ActiveRecord::Base
105
+ class Page < ApplicationRecord
95
106
  permalink :title, force: true
96
107
  end
97
108
  ```
98
109
 
99
110
  ## License
100
111
 
101
- Copyright (c) 2011-2015 Nando Vieira, released under the MIT license
112
+ Copyright (c) 2011-2024 Nando Vieira, released under the MIT license
102
113
 
103
114
  Permission is hereby granted, free of charge, to any person obtaining a copy of
104
115
  this software and associated documentation files (the "Software"), to deal in
@@ -105,9 +105,9 @@ module Permalink
105
105
  private def create_permalink
106
106
  return unless update_permalink?
107
107
 
108
- permalink = Permalink.generate(
108
+ permalink = Permalink.call(
109
109
  from_permalink_value.to_s,
110
- permalink_generator_options
110
+ **permalink_generator_options
111
111
  )
112
112
 
113
113
  write_attribute(
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Permalink
4
4
  module Version
5
- MAJOR = 2
6
- MINOR = 1
5
+ MAJOR = 3
6
+ MINOR = 0
7
7
  PATCH = 0
8
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
9
9
  end
10
10
  end
data/lib/permalink.rb CHANGED
@@ -19,13 +19,23 @@ module Permalink
19
19
  Normalizations::LeadingTrailingDashes
20
20
  ].freeze
21
21
 
22
+ DEFAULT_SEPARATOR = "-"
23
+
22
24
  DEFAULT_OPTIONS = {
23
25
  normalizations: DEFAULT_NORMALIZATIONS,
24
- separator: "-"
26
+ separator: DEFAULT_SEPARATOR
25
27
  }.freeze
26
28
 
27
- def self.generate(input, options = DEFAULT_OPTIONS)
28
- options = DEFAULT_OPTIONS.merge(options)
29
+ def self.active_record
30
+ ActiveRecord
31
+ end
32
+
33
+ def self.call(
34
+ input,
35
+ normalizations: DEFAULT_NORMALIZATIONS,
36
+ separator: DEFAULT_SEPARATOR
37
+ )
38
+ options = DEFAULT_OPTIONS.merge(normalizations:, separator:)
29
39
 
30
40
  options[:normalizations].each do |normalization|
31
41
  input = normalization.call(input, options)
@@ -33,6 +43,8 @@ module Permalink
33
43
 
34
44
  input
35
45
  end
36
- end
37
46
 
38
- ActiveRecord::Base.include Permalink::ActiveRecord
47
+ class << self
48
+ alias generate call
49
+ end
50
+ end
data/permalink.gemspec CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Generate permalink attributes on ActiveModel/ActiveRecord"
13
13
  s.description = s.summary
14
14
  s.license = "MIT"
15
- s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
+ s.required_ruby_version = Gem::Requirement.new(">= 3.2")
16
+ s.metadata["rubygems_mfa_required"] = "true"
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`
20
20
  .split("\n")
21
21
  .map {|f| File.basename(f) }
@@ -27,5 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency "rubocop"
28
28
  s.add_development_dependency "rubocop-fnando"
29
29
  s.add_development_dependency "simplecov"
30
- s.add_development_dependency "sqlite3"
30
+ s.add_development_dependency "sqlite3", "~> 1.4"
31
31
  end
@@ -11,7 +11,7 @@ class ActiveRecordTest < Minitest::Test
11
11
  end
12
12
 
13
13
  test "responds to options" do
14
- assert model.respond_to?(:permalink_options)
14
+ assert_respond_to model, :permalink_options
15
15
  end
16
16
 
17
17
  test "uses default options" do
@@ -63,10 +63,10 @@ class ActiveRecordTest < Minitest::Test
63
63
  another_user = User.create!
64
64
 
65
65
  # Create posts for user
66
- record = model.create(title: "Some nice post", user: user)
66
+ record = model.create(title: "Some nice post", user:)
67
67
  assert_equal "some-nice-post", record.permalink
68
68
 
69
- record = model.create(title: "Some nice post", user: user)
69
+ record = model.create(title: "Some nice post", user:)
70
70
  assert_equal "some-nice-post-2", record.permalink
71
71
 
72
72
  # Create posts for another user
@@ -5,7 +5,7 @@ require "test_helper"
5
5
  class PermalinkTest < Minitest::Test
6
6
  {
7
7
  "This IS a Tripped out title!!.!1 (well/ not really)" => "this-is-a-tripped-out-title-1-well-not-really", # rubocop:disable Layout/LineLength
8
- '////// meph1sto r0x ! \\\\\\' => "meph1sto-r0x",
8
+ "////// meph1sto r0x ! \\\\\\" => "meph1sto-r0x",
9
9
  "āčēģīķļņū" => "acegiklnu",
10
10
  "中文測試 chinese text" => "chinese-text",
11
11
  'some-)()()-ExtRa!/// .data==?> to \/\/test' => "some-extra-data-to-test",
@@ -16,7 +16,11 @@ class PermalinkTest < Minitest::Test
16
16
  "i'm a dog" => "im-a-dog"
17
17
  }.each do |from, to|
18
18
  test "creates permalink for #{from}" do
19
- assert_equal to, Permalink.generate(from)
19
+ assert_equal to, Permalink.call(from)
20
20
  end
21
21
  end
22
+
23
+ test "returns active record module" do
24
+ assert_equal Permalink::ActiveRecord, Permalink.active_record
25
+ end
22
26
  end
data/test/support/post.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Post < ActiveRecord::Base
4
+ include Permalink.active_record
4
5
  belongs_to :user
5
6
  end
@@ -6,6 +6,5 @@ ActiveRecord::Schema.define(version: 0) do
6
6
  t.belongs_to :user
7
7
  end
8
8
 
9
- create_table :users do |t|
10
- end
9
+ create_table :users
11
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permalink
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '1.4'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '1.4'
111
111
  description: Generate permalink attributes on ActiveModel/ActiveRecord
112
112
  email:
113
113
  - fnando.vieira@gmail.com
@@ -116,10 +116,12 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".github/FUNDING.yml"
119
+ - ".github/workflows/test.yml"
119
120
  - ".gitignore"
120
121
  - ".rubocop.yml"
121
- - ".travis.yml"
122
+ - CHANGELOG.md
122
123
  - Gemfile
124
+ - LICENSE.txt
123
125
  - README.md
124
126
  - Rakefile
125
127
  - lib/permalink.rb
@@ -142,7 +144,8 @@ files:
142
144
  homepage: http://rubygems.org/gems/permalink
143
145
  licenses:
144
146
  - MIT
145
- metadata: {}
147
+ metadata:
148
+ rubygems_mfa_required: 'true'
146
149
  post_install_message:
147
150
  rdoc_options: []
148
151
  require_paths:
@@ -151,22 +154,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
154
  requirements:
152
155
  - - ">="
153
156
  - !ruby/object:Gem::Version
154
- version: 2.5.0
157
+ version: '3.2'
155
158
  required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  requirements:
157
160
  - - ">="
158
161
  - !ruby/object:Gem::Version
159
162
  version: '0'
160
163
  requirements: []
161
- rubygems_version: 3.1.2
164
+ rubygems_version: 3.5.8
162
165
  signing_key:
163
166
  specification_version: 4
164
167
  summary: Generate permalink attributes on ActiveModel/ActiveRecord
165
- test_files:
166
- - test/permalink/active_record_test.rb
167
- - test/permalink/normalizations_test.rb
168
- - test/permalink/permalink_test.rb
169
- - test/support/post.rb
170
- - test/support/schema.rb
171
- - test/support/user.rb
172
- - test/test_helper.rb
168
+ test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- cache: bundler
2
- sudo: false
3
- rvm:
4
- - "2.7.1"
5
- - "2.6.5"
6
- notifications:
7
- email: false