tanshuku 4.0.1 → 5.0.0

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
  SHA256:
3
- metadata.gz: ceb5303a7a452e3b70b9d8c1873b627096804691a11388d59a7e79ed19192111
4
- data.tar.gz: 52d0b5ecb461972537aaa8998d60306a76f85327a8fa72f400fa7376e9fa2877
3
+ metadata.gz: 917b42fb5da1554baa82f02eab43fd54242c25205adca2d86375088e74587130
4
+ data.tar.gz: 84c3115dd375e421648438352b981464873478598e9be988d338c6f9a5d6bf68
5
5
  SHA512:
6
- metadata.gz: 5e1906a0852e7e982473a38fce39d49fc0ca8673e39ba17b906afe0bec0e27691f0e62e7f4a755507c4431d0baf9862cca089134ffab8cd3dca714df02af5b9e
7
- data.tar.gz: 9971952c5f6f59e62a8b0a1773297b224447fcf52abdd55ba28a1b64b8a3396bf01e848bf30107e5a1e4f24e1d808ffb06f421ea08acf1d673667dd42ae59d13
6
+ metadata.gz: c744a47b164d7d130ba6cc224c0041e08663fd123c9005588d15a786d94ff1b84e9c7976ea560e26c3f98169db104734a189e4837d25dc723613d3d441ca95da
7
+ data.tar.gz: c876d258f9392e80c0f6093041ce800aa4e5754506793325deb66c3b0391f8b90e632d90743362005aa0726eb20dc45bd9a107ecdb22c29da4c3f972f2f0b13b
@@ -9,7 +9,7 @@ module Tanshuku
9
9
  #
10
10
  # @raise [ActiveRecord::NotFound] If no {Tanshuku::Url} record is found for the given +key+.
11
11
  def show
12
- url = Url.find_by!(key: params[:key])
12
+ url = Url.find_by!(key: params.expect(:key))
13
13
  redirect_to url.url, status: :moved_permanently, allow_other_host: true
14
14
  end
15
15
  end
@@ -169,9 +169,11 @@ module Tanshuku
169
169
  # @return [String] A shortened URL.
170
170
  #
171
171
  # @note
172
- # In Rails 8.0 or later, this method loads the routes before calling +url_for+ as Tanshuku depends on them.
172
+ # This method loads the routes before calling +url_for+ as Tanshuku depends on them.
173
173
  # cf. https://github.com/rails/rails/pull/52353
174
174
  def shortened_url(url_options = {})
175
+ Rails.application.reload_routes_unless_loaded
176
+
175
177
  url_options = url_options.symbolize_keys
176
178
  url_options[:controller] = "tanshuku/urls"
177
179
  url_options[:action] = :show
@@ -179,25 +181,6 @@ module Tanshuku
179
181
 
180
182
  Tanshuku::Engine.routes.url_for(url_options)
181
183
  end
182
-
183
- case Gem::Version.new(Rails.version)
184
- when "7.0"..."8.0"
185
- # Don’t define `#shortened_url` in this branch because YARD doesn’t recognize the method.
186
- else
187
- # Overwrite the `#shortened_url` in Rails 8.0 or later.
188
- # rubocop:disable Lint/DuplicateMethods
189
- def shortened_url(url_options = {})
190
- Rails.application.reload_routes_unless_loaded
191
-
192
- url_options = url_options.symbolize_keys
193
- url_options[:controller] = "tanshuku/urls"
194
- url_options[:action] = :show
195
- url_options[:key] = key
196
-
197
- Tanshuku::Engine.routes.url_for(url_options)
198
- end
199
- # rubocop:enable Lint/DuplicateMethods
200
- end
201
184
  end
202
185
  # rubocop:enable Rails/ApplicationRecord
203
186
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CreateTanshukuUrls < ActiveRecord::Migration[7.0]
3
+ class CreateTanshukuUrls < ActiveRecord::Migration[Rails::VERSION::STRING.to_f]
4
4
  def change
5
5
  create_table :tanshuku_urls do |t|
6
6
  t.text :url, null: false
@@ -11,7 +11,7 @@ class CreateTanshukuUrls < ActiveRecord::Migration[7.0]
11
11
  # You might adjust the `limit: 20` depending on `.key_length` and `.key_generator` of `Tanshuku.config`.
12
12
  t.string :key, null: false, limit: 20, index: { unique: true }, comment: "cf. Tanshuku::Url.generate_key"
13
13
 
14
- t.datetime :created_at, null: false, precision: nil
14
+ t.datetime :created_at, null: false
15
15
  end
16
16
  end
17
17
  end
@@ -24,8 +24,15 @@ module Tanshuku
24
24
  # rubocop:disable Rails/TimeZone
25
25
  old_filename = "20230220123456_create_tanshuku_urls.rb"
26
26
  new_filename = old_filename.sub("20230220123456", Time.now.strftime("%Y%m%d%H%M%S"))
27
- copy_file "../../../db/migrate/#{old_filename}", "db/migrate/#{new_filename}"
28
27
  # rubocop:enable Rails/TimeZone
28
+
29
+ old_filepath = "../../../db/migrate/#{old_filename}"
30
+ new_filepath = "db/migrate/#{new_filename}"
31
+
32
+ copy_file old_filepath, new_filepath
33
+
34
+ # rubocop:disable-next Lint/NumberConversion
35
+ gsub_file new_filepath, "Rails::VERSION::STRING.to_f", Rails::VERSION::STRING.to_f.to_s
29
36
  end
30
37
  end
31
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- VERSION = "4.0.1"
4
+ VERSION = "5.0.0"
5
5
  end
data/lib/tanshuku.rb CHANGED
@@ -15,9 +15,8 @@ module Tanshuku
15
15
  # {Tanshuku.configure} for configuration.
16
16
  def self.config
17
17
  # Disable this cop but use `Tanshuku::Configuration#configure` for thread-safety.
18
- # rubocop:disable ThreadSafety/ClassInstanceVariable
18
+ # rubocop:disable-next ThreadSafety/ClassInstanceVariable
19
19
  @config ||= Configuration.new
20
- # rubocop:enable ThreadSafety/ClassInstanceVariable
21
20
  end
22
21
 
23
22
  # Configures Tanshuku.
@@ -1,5 +1,5 @@
1
1
  module Tanshuku
2
2
  class UrlsController < ActionController::API
3
- def show: -> void
3
+ def show: () -> void
4
4
  end
5
5
  end
@@ -107,7 +107,7 @@ module Tanshuku
107
107
  def self.find_by_url: (String url, ?namespace: String) -> Tanshuku::Url?
108
108
  def self.normalize_url: (String url) -> String
109
109
  def self.hash_url: (String url, ?namespace: String) -> String
110
- def self.generate_key: -> String
110
+ def self.generate_key: () -> String
111
111
  def self.report_exception: (exception: Exception, original_url: String) -> void
112
112
  def shortened_url: (?Hash[String | Symbol, untyped] url_options) -> String
113
113
  end
@@ -1,2 +1,3 @@
1
- class CreateTanshukuUrls < ActiveRecord::Migration::Compatibility::V7_0
1
+ class CreateTanshukuUrls < ActiveRecord::Migration::Current
2
+ def change: () -> void
2
3
  end
@@ -1,4 +1,6 @@
1
1
  module Tanshuku
2
2
  class InstallGenerator < Rails::Generators::Base
3
+ def copy_initializer_file: () -> void
4
+ def copy_migration_file: () -> void
3
5
  end
4
6
  end
@@ -5,7 +5,7 @@ module Tanshuku
5
5
  end
6
6
 
7
7
  interface _KeyGenerator
8
- def call: -> String
8
+ def call: () -> String
9
9
  end
10
10
 
11
11
  interface _ExceptionReporter
@@ -25,7 +25,7 @@ module Tanshuku
25
25
  attr_accessor exception_reporter (): _ExceptionReporter
26
26
 
27
27
  def initialize: (*bot noname) -> void
28
- def configure: { (Configuration) -> void } -> void
28
+ def configure: () { (Configuration) -> void } -> void
29
29
 
30
30
  module DefaultUrlHasher
31
31
  extend _UrlHasher
data/sig/lib/tanshuku.rbs CHANGED
@@ -1,6 +1,6 @@
1
1
  module Tanshuku
2
2
  self.@config: Configuration
3
3
 
4
- def self.config: -> Configuration
5
- def self.configure: { (Configuration config) -> void } -> void
4
+ def self.config: () -> Configuration
5
+ def self.configure: () { (Configuration config) -> void } -> void
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanshuku
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kg8m
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: addressable
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '2.4'
18
+ version: '2.8'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '2.4'
25
+ version: '2.8'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '8.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.0'
39
+ version: '8.0'
40
40
  description: Tanshuku is a simple and performance aware Rails engine for shortening
41
41
  URLs. Tanshuku generates a shortened URL per a normalized original URL. Tanshuku
42
42
  redirects from a shortened URL to its corresponding original URL.
@@ -60,7 +60,6 @@ files:
60
60
  - lib/tanshuku/configuration.rb
61
61
  - lib/tanshuku/engine.rb
62
62
  - lib/tanshuku/version.rb
63
- - lib/tasks/check_all.rb
64
63
  - sig/app/controllers/tanshuku/urls_controller.rbs
65
64
  - sig/app/models/tanshuku/url.rbs
66
65
  - sig/db/migrate/create_tanshuku_urls.rbs
@@ -69,7 +68,6 @@ files:
69
68
  - sig/lib/tanshuku/configuration.rbs
70
69
  - sig/lib/tanshuku/engine.rbs
71
70
  - sig/lib/tanshuku/version.rbs
72
- - sig/lib/tasks/check_all.rbs
73
71
  homepage: https://github.com/kg8m/tanshuku
74
72
  licenses:
75
73
  - MIT
@@ -86,14 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
84
  requirements:
87
85
  - - ">="
88
86
  - !ruby/object:Gem::Version
89
- version: '3.2'
87
+ version: '3.3'
90
88
  required_rubygems_version: !ruby/object:Gem::Requirement
91
89
  requirements:
92
90
  - - ">="
93
91
  - !ruby/object:Gem::Version
94
92
  version: '0'
95
93
  requirements: []
96
- rubygems_version: 3.6.2
94
+ rubygems_version: 4.0.24
97
95
  specification_version: 4
98
96
  summary: Tanshuku is a simple and performance aware Rails engine for shortening URLs.
99
97
  test_files: []
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "English"
4
- require "io/console"
5
- require "paint"
6
- require "pty"
7
-
8
- class CheckAll
9
- TASKNAMES = %i[rubocop spec steep:check yard:check].freeze
10
- LINE = Paint["-" * (IO.console or raise).winsize[1], :bold]
11
- TITLE_TEMPLATE = Paint["\n#{LINE}\nExecute: %<command>s\n#{LINE}\n\n", :bold]
12
-
13
- attr_reader :failed_commands
14
-
15
- def self.call
16
- new.call
17
- end
18
-
19
- def initialize
20
- @failed_commands = []
21
- end
22
-
23
- def call
24
- # rubocop:disable ThreadSafety/NewThread
25
- TASKNAMES.map { |taskname| Thread.new(taskname, &executor) }.each(&:join)
26
- # rubocop:enable ThreadSafety/NewThread
27
- output_result
28
- end
29
-
30
- private
31
-
32
- def executor
33
- lambda do |taskname|
34
- command = "bundle exec rake #{taskname}"
35
-
36
- outputs = [] #: Array[String]
37
- outputs << format(TITLE_TEMPLATE, command:)
38
-
39
- # Use `PTY.spawn` to get colorized outputs of each command.
40
- PTY.spawn(command) do |reader, writer, pid|
41
- writer.close
42
-
43
- while (output = reader.gets)
44
- outputs << output
45
- end
46
-
47
- Process.wait(pid)
48
- end
49
- failed_commands << command unless $CHILD_STATUS&.success?
50
-
51
- puts outputs.join
52
- end
53
- end
54
-
55
- def output_result
56
- puts ""
57
- puts LINE
58
- puts Paint["Result", :bold]
59
- puts LINE
60
-
61
- if failed_commands.empty?
62
- puts Paint["\nAll checks are OK.", :green, :bold]
63
- else
64
- puts Paint["\nChecks failed!!\n", :red, :bold]
65
- puts failed_commands.map { |command| " - #{command}" }.join("\n")
66
- abort ""
67
- end
68
- end
69
- end
@@ -1,18 +0,0 @@
1
- class CheckAll
2
- TASKNAMES: Array[Symbol]
3
- LINE: String
4
- TITLE_TEMPLATE: String
5
-
6
- attr_reader failed_commands: Array[String]
7
-
8
- def initialize: () -> void
9
-
10
- def self.call: () -> void
11
-
12
- def call: () -> void
13
-
14
- private
15
-
16
- def executor: () -> ^(*String) -> void
17
- def output_result: () -> void
18
- end