tanshuku 0.0.19 → 1.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: 0ed630fab007e97649b1a2517683823bf23c4fef612c21bbd87e31f8e34647b5
4
- data.tar.gz: c2d9fa9e3e3f173fd69ccaf5826ce4e9cc0adea43729410fda75c0d10d6e60da
3
+ metadata.gz: 92f985a414af971db170f5ce9a171469af6901f47feb4345a3b8ad96d256854e
4
+ data.tar.gz: 64a303579eb92b6748332d1f15259d4de493c11d32d572fd98a539269f3fffda
5
5
  SHA512:
6
- metadata.gz: c38c594c794df3292bea69efe4446b12a5cb8ce807abcc967e1bc93d2bc1910c41a5d57caa24a465737991277c6523f78a455dbd8ec32d669276f6f7f7bfb06e
7
- data.tar.gz: b30d56b5b4fb085f59a0cb4e2c51a9bf661dfae892a6d349138b14a374b7233777341e8f9914d13f2d121e06caee0534ca56c6552e24db8779494a6b1118b360
6
+ metadata.gz: e5cd414ab9fcebdb55fa961744ac339d668466200972dfd8e0cc0b46a567f183fc00541cb3ffe784173d1eda3fa63f7c2c796eeee5488b7e396d9fb8dd98ff3e
7
+ data.tar.gz: f5f1e7a1d50cb26f2e61973903e708e255e2bb76248c6e7e7d14b74dd55a6fbb9a13a842dc2f8bf0f33cc7aae70bf33b500e5a337c8fc3af910a60ce108b8f88
data/README.md CHANGED
@@ -4,19 +4,19 @@ Tanshuku is a simple and small Rails engine that makes it easier to shorten URLs
4
4
 
5
5
  ## Key Features
6
6
 
7
- * Generates a unique key for a URL.
8
- * The uniqueness is ensured at database level.
9
- * Creates no additional shortened URL record if the given URL has already been shortened.
10
- * You can create an additional record for the same URL with using a different namespace from existing records'.
11
- * Checks its existence considering the performance.
12
- * Provides a Rails controller and action for finding a shortened URL record and redirecting to its original, i.e., non-shortened, URL.
13
- * The redirection is done with 301 HTTP status.
7
+ - Generates a unique key for a URL.
8
+ - The uniqueness is ensured at database level.
9
+ - Creates no additional shortened URL record if the given URL has already been shortened.
10
+ - You can create an additional record for the same URL with using a different namespace from existing records’.
11
+ - Checks its existence considering the performance.
12
+ - Provides a Rails controller and action for finding a shortened URL record and redirecting to its original, i.e., non-shortened, URL.
13
+ - The redirection is done with 301 HTTP status.
14
14
 
15
15
  ## Usage
16
16
 
17
17
  ### 1. Mount `Tanshuku::Engine`
18
18
 
19
- For example, the following code generates a routing `` GET `/t/:key` to `Tanshuku::UrlsController#show` ``. When your Rails app receives a request to `/t/abcdefghij0123456789`, `Tanshuku::UrlsController#show` will be called and a `Tanshuku::Url` record with a key `abcdefghij0123456789` will be found. Then the request will be redirected to the `Tanshuku::Url` record's original URL.
19
+ For example, the following code generates a routing `` GET `/t/:key` to `Tanshuku::UrlsController#show` ``. When your Rails app receives a request to `/t/abcdefghij0123456789`, `Tanshuku::UrlsController#show` will be called and a `Tanshuku::Url` record with a key `abcdefghij0123456789` will be found. Then the request will be redirected to the `Tanshuku::Url` records original URL.
20
20
 
21
21
  ```rb
22
22
  # config/routes.rb
@@ -31,9 +31,9 @@ end
31
31
 
32
32
  **Note**: This step is optional.
33
33
 
34
- **Note**: An initializer file for configuration can be generated by `bin/rails generate tanshuku:install`. See the "[Installation](#installation)" section below for more information.
34
+ **Note**: An initializer file for configuration can be generated by `bin/rails generate tanshuku:install`. See the [Installation](#installation) section below for more information.
35
35
 
36
- **Note**: Mutating a `Tanshuku::Configuration` object is thread-***unsafe***. It is recommended to use `Tanshuku.configure` for configuration.
36
+ **Note**: Mutating a `Tanshuku::Configuration` object is thread-**_unsafe_**. It is recommended to use `Tanshuku.configure` for configuration.
37
37
 
38
38
  #### `config.default_url_options`
39
39
 
@@ -65,14 +65,14 @@ The following example means that an exception and a URL will be reported to [Sen
65
65
  Tanshuku.configure do |config|
66
66
  config.exception_reporter =
67
67
  lambda { |exception:, original_url:|
68
- Sentry.capture_exception(exception, tags: { original_url: })
68
+ Sentry.capture_exception(exception, tags: { original_url: original_url })
69
69
  }
70
70
  end
71
71
  ```
72
72
 
73
73
  #### More information
74
74
 
75
- cf. [`Tanshuku::Configuration`'s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Configuration.html)
75
+ cf. [`Tanshuku::Configuration`’s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Configuration.html)
76
76
 
77
77
  ### 3. Generate shortened URLs
78
78
 
@@ -115,10 +115,10 @@ Tanshuku::Url.shorten("https://google.com/", url_options: { protocol: :http })
115
115
  You can create additional records for the same URL with specifying a namespace.
116
116
 
117
117
  ```rb
118
- # When no record exists for "https://google.com/", a new record will be created.
118
+ # When no record exists for https://google.com/”, a new record will be created.
119
119
  Tanshuku::Url.shorten("https://google.com/") #=> "https://example.com/t/abc012def345ghi678j9"
120
120
 
121
- # Even when a record already exists for "https://google.com/", an additional record will be created if namespace is
121
+ # Even when a record already exists for https://google.com/”, an additional record will be created if namespace is
122
122
  # specified.
123
123
  Tanshuku::Url.shorten("https://google.com/", namespace: "a") #=> "https://example.com/t/ab01cd23ef45gh67ij89"
124
124
  Tanshuku::Url.shorten("https://google.com/", namespace: "b") #=> "https://example.com/t/a0b1c2d3e4f5g6h7i8j9"
@@ -131,7 +131,7 @@ Tanshuku::Url.shorten("https://google.com/", namespace: "a") #=> "https://examp
131
131
 
132
132
  #### More information
133
133
 
134
- cf. [`Tanshuku::Url.shorten`'s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Url.html#shorten-class_method)
134
+ cf. [`Tanshuku::Url.shorten`’s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Url.html#shorten-class_method)
135
135
 
136
136
  ### 4. Share the shortened URLs
137
137
 
@@ -143,7 +143,7 @@ When a user clicks a link with a shortened URL, your Rails app redirects the use
143
143
 
144
144
  ### 1. Enable Tanshuku
145
145
 
146
- Add `gem "tanshuku"` to your application's `Gemfile`.
146
+ Add `gem "tanshuku"` to your applications `Gemfile`.
147
147
 
148
148
  ```rb
149
149
  # Gemfile
@@ -168,13 +168,13 @@ bin/rails db:migrate
168
168
 
169
169
  ## Q&A
170
170
 
171
- ### What does "tanshuku" mean?
171
+ ### Q. What does tanshuku mean?
172
172
 
173
- "Tanshuku" is a Japanese word "短縮." It means "shortening." "短縮URL" in Japanese means "shortened URL" in English.
173
+ A. “Tanshuku is a Japanese word “短縮.” It means shortening.” And “短縮URL in Japanese means shortened URL in English.
174
174
 
175
- ### \*\* (anything you want) isn't implemented?
175
+ ### Q. \*\* (anything you want) isnt implemented?
176
176
 
177
- Does Tanshuku have some missing features? Please [create an issue](https://github.com/kg8m/tanshuku/issues/new).
177
+ A. Does Tanshuku have some missing features? Please [create an issue](https://github.com/kg8m/tanshuku/issues/new).
178
178
 
179
179
  ## How to develop
180
180
 
@@ -13,7 +13,7 @@ module Tanshuku
13
13
  # @return [String] Original, i.e., non-shortened, URL of the record.
14
14
  #
15
15
  # @!attribute [rw] hashed_url
16
- # @return [String] A hashed string of the record's original URL.
16
+ # @return [String] A hashed string of the records original URL.
17
17
  # @note This attribute is used for uniqueness of the original URL.
18
18
  # @api private
19
19
  #
@@ -26,15 +26,16 @@ module Tanshuku
26
26
  DEFAULT_NAMESPACE = ""
27
27
 
28
28
  validates :url, :hashed_url, :key, presence: true
29
- validates :url, length: { maximum: proc { Tanshuku.config.max_url_length } }
30
29
  validates :url, format: { with: proc { Tanshuku.config.url_pattern } }, allow_blank: true
31
30
 
32
- # Don't validate uniqueness of unique attributes. Raise ActiveRecord::RecordNotUnique instead if the attributes get
31
+ # Dont validate uniqueness of unique attributes. Raise ActiveRecord::RecordNotUnique instead if the attributes get
32
+ validate :validates_length_of_url
33
+
33
34
  # duplicated. Then rescue the exception and try to retry.
34
35
  # validates :url, :hashed_url, :key, uniqueness: true
35
36
 
36
37
  # Shortens a URL. Builds and saves a {Tanshuku::Url} record with generating a unique key for the given URL and
37
- # namespace. Then returns the record's shortened URL with the given URL options.
38
+ # namespace. Then returns the records shortened URL with the given URL options.
38
39
  #
39
40
  # @note
40
41
  # If a {Tanshuku::Url} record already exists, no additional record will be created and the existing record will be
@@ -45,7 +46,7 @@ module Tanshuku
45
46
  #
46
47
  # @param original_url [String] The original, i.e., non-shortened, URL.
47
48
  # @param namespace [String] A namespace for shorteting URL. Shortened URLs are unique in namespaces.
48
- # @param url_options [Hash] An option for Rails' +url_for+.
49
+ # @param url_options [Hash] An option for Rails +url_for+.
49
50
  #
50
51
  # @return [String] A shortened URL if succeeded to shorten the original URL.
51
52
  # @return [String] The original URL if failed to shorten it.
@@ -61,10 +62,10 @@ module Tanshuku
61
62
  # Tanshuku::Url.shorten("https://google.com/", url_options: { protocol: :http })
62
63
  # #=> "http://example.com/t/abcde01234fghij56789"
63
64
  # @example With a namespace.
64
- # # When no record exists for "https://google.com/", a new record will be created.
65
+ # # When no record exists for https://google.com/”, a new record will be created.
65
66
  # Tanshuku::Url.shorten("https://google.com/") #=> "https://example.com/t/abc012def345ghi678j9"
66
67
  #
67
- # # Even when a record already exists for "https://google.com/", an additional record will be created if namespace
68
+ # # Even when a record already exists for https://google.com/”, an additional record will be created if namespace
68
69
  # # is specified.
69
70
  # Tanshuku::Url.shorten("https://google.com/", namespace: "a") #=> "https://example.com/t/ab01cd23ef45gh67ij89"
70
71
  # Tanshuku::Url.shorten("https://google.com/", namespace: "b") #=> "https://example.com/t/a0b1c2d3e4f5g6h7i8j9"
@@ -82,8 +83,8 @@ module Tanshuku
82
83
  begin
83
84
  transaction do
84
85
  record =
85
- create_or_find_by!(hashed_url: hash_url(url, namespace:)) do |r|
86
- r.attributes = { url:, key: generate_key }
86
+ create_or_find_by!(hashed_url: hash_url(url, namespace: namespace)) do |r|
87
+ r.attributes = { url: url, key: generate_key }
87
88
  end
88
89
 
89
90
  record.shortened_url(url_options)
@@ -94,15 +95,24 @@ module Tanshuku
94
95
  retries += 1
95
96
  retry
96
97
  else
97
- report_exception(exception: e, original_url:)
98
+ report_exception(exception: e, original_url: original_url)
98
99
  original_url
99
100
  end
100
101
  end
101
102
  rescue StandardError => e
102
- report_exception(exception: e, original_url:)
103
+ report_exception(exception: e, original_url: original_url)
103
104
  original_url
104
105
  end
105
106
 
107
+ unless respond_to?(:create_or_find_by!)
108
+ # https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/relation.rb#L218-L222
109
+ def self.create_or_find_by!(attributes, &block)
110
+ transaction(requires_new: true) { create!(attributes, &block) }
111
+ rescue ActiveRecord::RecordNotUnique
112
+ find_by!(attributes)
113
+ end
114
+ end
115
+
106
116
  # Finds a {Tanshuku::Url} record by a non-shortened URL.
107
117
  #
108
118
  # @param url [String] A non-shortened URL.
@@ -112,9 +122,9 @@ module Tanshuku
112
122
  # @return [nil] +nil+ unless found.
113
123
  def self.find_by_url(url, namespace: DEFAULT_NAMESPACE)
114
124
  normalized_url = normalize_url(url)
115
- hashed_url = hash_url(normalized_url, namespace:)
125
+ hashed_url = hash_url(normalized_url, namespace: namespace)
116
126
 
117
- find_by(hashed_url:)
127
+ find_by(hashed_url: hashed_url)
118
128
  end
119
129
 
120
130
  # Normalizes a URL. Adds or removes a trailing slash, removes +?+ for an empty query, and so on. And sorts query
@@ -131,19 +141,19 @@ module Tanshuku
131
141
 
132
142
  # Hashes a URL.
133
143
  #
134
- # @note This method calls {Tanshuku::Configuration#url_hasher}'s +call+ and returns its return value.
144
+ # @note This method calls {Tanshuku::Configuration#url_hasher}s +call+ and returns its return value.
135
145
  #
136
146
  # @param url [String] A non-hashed URL.
137
147
  # @param namespace [String] A namespace for the URL.
138
148
  #
139
149
  # @return [String] Depends on your {Tanshuku::Configuration#url_hasher} configuration.
140
150
  def self.hash_url(url, namespace: DEFAULT_NAMESPACE)
141
- Tanshuku.config.url_hasher.call(url, namespace:)
151
+ Tanshuku.config.url_hasher.call(url, namespace: namespace)
142
152
  end
143
153
 
144
154
  # Generates a unique key for a shortened URL.
145
155
  #
146
- # @note This method calls {Tanshuku::Configuration#key_generator}'s +call+ and returns its return value.
156
+ # @note This method calls {Tanshuku::Configuration#key_generator}s +call+ and returns its return value.
147
157
  #
148
158
  # @return [String] Depends on your {Tanshuku::Configuration#key_generator} configuration.
149
159
  def self.generate_key
@@ -152,19 +162,19 @@ module Tanshuku
152
162
 
153
163
  # Reports an exception when failed to shorten a URL.
154
164
  #
155
- # @note This method calls {Tanshuku::Configuration#exception_reporter}'s +call+ and returns its return value.
165
+ # @note This method calls {Tanshuku::Configuration#exception_reporter}s +call+ and returns its return value.
156
166
  #
157
167
  # @param exception [Exception] An error instance at shortening a URL.
158
168
  # @param original_url [String] The original URL failed to shorten.
159
169
  #
160
170
  # @return [void] Depends on your {Tanshuku::Configuration#exception_reporter} configuration.
161
171
  def self.report_exception(exception:, original_url:)
162
- Tanshuku.config.exception_reporter.call(exception:, original_url:)
172
+ Tanshuku.config.exception_reporter.call(exception: exception, original_url: original_url)
163
173
  end
164
174
 
165
- # The record's shortened URL.
175
+ # The records shortened URL.
166
176
  #
167
- # @param url_options [Hash] An option for Rails' +url_for+.
177
+ # @param url_options [Hash] An option for Rails +url_for+.
168
178
  #
169
179
  # @return [String] A shortened URL.
170
180
  def shortened_url(url_options = {})
@@ -175,6 +185,14 @@ module Tanshuku
175
185
 
176
186
  Tanshuku::Engine.routes.url_for(url_options)
177
187
  end
188
+
189
+ private
190
+
191
+ def validates_length_of_url
192
+ if url && url.length > Tanshuku.config.max_url_length
193
+ errors.add(:url, :too_long, count: Tanshuku.config.max_url_length)
194
+ end
195
+ end
178
196
  end
179
197
  # rubocop:enable Rails/ApplicationRecord
180
198
  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[5.1]
4
4
  def change
5
5
  create_table :tanshuku_urls do |t|
6
6
  t.text :url, null: false
@@ -7,8 +7,7 @@ module Tanshuku
7
7
  #
8
8
  # @api private
9
9
  class InstallGenerator < Rails::Generators::Base
10
- # Assign `_ = __dir__` because Steep reports `__dir__` which can be a `nil` but I don’t want to care about that.
11
- source_root File.expand_path("../templates", _ = __dir__)
10
+ source_root File.expand_path("../templates", __dir__)
12
11
 
13
12
  # Generates a configuration file +config/initializers/tanshuku.rb+.
14
13
  #
@@ -11,7 +11,7 @@ module Tanshuku
11
11
  # Calls +Digest::SHA512.hexdigest+ with the given URL string and the given namespace.
12
12
  #
13
13
  # @param url [String] A URL to hash.
14
- # @param namespace [String] A namespace for the URL's uniqueness.
14
+ # @param namespace [String] A namespace for the URLs uniqueness.
15
15
  #
16
16
  # @return [String] A SHA512 digest string from the given url and namespace.
17
17
  def self.call(url, namespace:)
@@ -42,10 +42,71 @@ module Tanshuku
42
42
  end
43
43
  end
44
44
 
45
- include ActiveModel::Attributes
45
+ if defined?(ActiveModel::Attributes)
46
+ include ActiveModel::Attributes
47
+ else
48
+ # https://github.com/rails/rails/blob/v5.2.8.1/activemodel/lib/active_model/attributes.rb
49
+ # https://github.com/rails/rails/blob/v5.2.8.1/activemodel/lib/active_model/type/integer.rb
50
+ concerning :PetitModelAttributes do
51
+ const_set :NO_DEFAULT_PROVIDED, Object.new
52
+
53
+ class_methods do
54
+ # rubocop:disable Metrics/MethodLength
55
+
56
+ # A petit and limited implementation of `ActiveModel::Attributes`'s `attribute` method for backward
57
+ # compatibility.
58
+ #
59
+ # @param name [Symbol] An attribute name.
60
+ # @param cast_type [Symbol,nil] A type to cast the attribute's value.
61
+ # @param default [Object] A default value of the attribute.
62
+ #
63
+ # @return [void]
64
+ def attribute(name, cast_type = nil, default: NO_DEFAULT_PROVIDED)
65
+ attr_reader name
66
+
67
+ case cast_type
68
+ when nil
69
+ attr_writer name
70
+ when :integer
71
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
72
+ def #{name}=(value) # def max_url_length=(value)
73
+ @#{name} = # @max_url_length =
74
+ case value # case value
75
+ when true # when true
76
+ 1 # 1
77
+ when false # when false
78
+ 0 # 0
79
+ when nil # when nil
80
+ nil # nil
81
+ else # else
82
+ value.to_i rescue nil # value.to_i rescue nil
83
+ end # end
84
+ end # end
85
+ RUBY
86
+ else
87
+ raise ArgumentError, "Non-supported cast type: #{cast_type.inspect}"
88
+ end
89
+
90
+ return if default == NO_DEFAULT_PROVIDED
91
+
92
+ mod =
93
+ Module.new do
94
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
95
+ def initialize(*args) # def initialize(*args)
96
+ super # super
97
+ self.#{name} = #{default.inspect} # self.max_url_length = 10_000
98
+ end # end
99
+ RUBY
100
+ end
101
+ prepend mod
102
+ end
103
+ # rubocop:enable Metrics/MethodLength
104
+ end
105
+ end
106
+ end
46
107
 
47
108
  # @!attribute [rw] default_url_options
48
- # Default URL options for Rails' +url_for+. Defaults to +{}+.
109
+ # Default URL options for Rails +url_for+. Defaults to +{}+.
49
110
  #
50
111
  # @return [Hash]
51
112
  # @return [void] If you set an invalid object.
@@ -102,7 +163,7 @@ module Tanshuku
102
163
  # @return [Integer]
103
164
  # @return [void] If you set an invalid object.
104
165
  #
105
- # @note Don't forget to fix the limit of the +tanshuku_urls.key+ column if you change this value.
166
+ # @note Dont forget to fix the limit of the +tanshuku_urls.key+ column if you change this value.
106
167
  #
107
168
  # @note
108
169
  # The example below means that {Tanshuku::Url#key} has 10-char string.
@@ -166,12 +227,12 @@ module Tanshuku
166
227
  # Tanshuku.configure do |config|
167
228
  # config.exception_reporter =
168
229
  # lambda { |exception:, original_url:|
169
- # Sentry.capture_exception(exception, tags: { original_url: })
230
+ # Sentry.capture_exception(exception, tags: { original_url: original_url })
170
231
  # }
171
232
  # end
172
233
  attribute :exception_reporter, default: DefaultExceptionReporter
173
234
 
174
- def initialize(...)
235
+ def initialize(*args)
175
236
  super
176
237
  @mutex = Mutex.new
177
238
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- # Tanshuku's Rails engine.
4
+ # Tanshukus Rails engine.
5
5
  #
6
6
  # @note
7
7
  # The example below generates a routing +GET `/t/:key` to `Tanshuku::UrlsController#show`+. When your Rails app
8
8
  # receives a request to +/t/abcdefghij0123456789+, +Tanshuku::UrlsController#show+ will be called and a
9
9
  # +Tanshuku::Url+ record with a key +abcdefghij0123456789+ will be found. Then the request will be redirected to the
10
- # +Tanshuku::Url+ record's original URL.
10
+ # +Tanshuku::Url+ records original URL.
11
11
  #
12
12
  # @example To mount Tanshuku to your Rails app
13
13
  # # config/routes.rb
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- VERSION = "0.0.19"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/tanshuku.rb CHANGED
@@ -4,7 +4,7 @@ require_relative "tanshuku/configuration"
4
4
  require_relative "tanshuku/engine"
5
5
  require_relative "tanshuku/version"
6
6
 
7
- # Tanshuku's namespace.
7
+ # Tanshukus namespace.
8
8
  module Tanshuku
9
9
  # Returns a configuration object for Tanshuku.
10
10
  #
@@ -35,7 +35,7 @@ module Tanshuku
35
35
  # Tanshuku.configure do |config|
36
36
  # config.default_url_options = { host: "localhost", protocol: :https }
37
37
  # end
38
- def self.configure(&)
39
- config.configure(&)
38
+ def self.configure(&block)
39
+ config.configure(&block)
40
40
  end
41
41
  end
@@ -0,0 +1,67 @@
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 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
+ TASKNAMES.map { |taskname| Thread.new(taskname, &executor) }.each(&:join)
25
+ output_result
26
+ end
27
+
28
+ private
29
+
30
+ def executor
31
+ lambda do |taskname|
32
+ command = "bundle exec rake #{taskname}"
33
+
34
+ outputs = []
35
+ outputs << format(TITLE_TEMPLATE, command: command)
36
+
37
+ # Use `PTY.spawn` to get colorized outputs of each command.
38
+ PTY.spawn(command) do |reader, writer, pid|
39
+ writer.close
40
+
41
+ while (output = reader.gets)
42
+ outputs << output
43
+ end
44
+
45
+ Process.wait(pid)
46
+ end
47
+ failed_commands << command unless $CHILD_STATUS&.success?
48
+
49
+ puts outputs.join
50
+ end
51
+ end
52
+
53
+ def output_result
54
+ puts ""
55
+ puts LINE
56
+ puts Paint["Result", :bold]
57
+ puts LINE
58
+
59
+ if failed_commands.empty?
60
+ puts Paint["\nAll checks are OK.", :green, :bold]
61
+ else
62
+ puts Paint["\nChecks failed!!\n", :red, :bold]
63
+ puts failed_commands.map { |command| " - #{command}" }.join("\n")
64
+ abort ""
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanshuku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kg8m
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-25 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.0
19
+ version: '2.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.0
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 7.0.0
33
+ version: '5.1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
- version: 7.0.0
43
+ version: '5.1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
41
47
  description: Tanshuku is a simple and performance aware Rails engine for shortening
42
48
  URLs. Tanshuku generates a shortened URL per a normalized original URL. Tanshuku
43
49
  redirects from a shortened URL to its corresponding original URL.
@@ -49,7 +55,6 @@ extra_rdoc_files: []
49
55
  files:
50
56
  - LICENSE
51
57
  - README.md
52
- - Steepfile
53
58
  - app/controllers/tanshuku/urls_controller.rb
54
59
  - app/models/tanshuku/url.rb
55
60
  - config/locales/en.yml
@@ -62,16 +67,7 @@ files:
62
67
  - lib/tanshuku/configuration.rb
63
68
  - lib/tanshuku/engine.rb
64
69
  - lib/tanshuku/version.rb
65
- - rbs_collection.lock.yaml
66
- - rbs_collection.yaml
67
- - sig/app/controllers/tanshuku/urls_controller.rbs
68
- - sig/app/models/tanshuku/url.rbs
69
- - sig/db/migrate/create_tanshuku_urls.rbs
70
- - sig/lib/generators/tanshuku/install_generator.rbs
71
- - sig/lib/tanshuku.rbs
72
- - sig/lib/tanshuku/configuration.rbs
73
- - sig/lib/tanshuku/engine.rbs
74
- - sig/lib/tanshuku/version.rbs
70
+ - lib/tasks/check_all.rb
75
71
  homepage: https://github.com/kg8m/tanshuku
76
72
  licenses:
77
73
  - MIT
@@ -89,14 +85,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
85
  requirements:
90
86
  - - ">="
91
87
  - !ruby/object:Gem::Version
92
- version: '3.1'
88
+ version: '2.5'
89
+ - - "<"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.0'
93
92
  required_rubygems_version: !ruby/object:Gem::Requirement
94
93
  requirements:
95
94
  - - ">="
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
97
  requirements: []
99
- rubygems_version: 3.4.10
98
+ rubygems_version: 3.1.6
100
99
  signing_key:
101
100
  specification_version: 4
102
101
  summary: Tanshuku is a simple and performance aware Rails engine for shortening URLs.
data/Steepfile DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- target :main do
4
- check "app", "config", "db", "lib"
5
- signature "sig"
6
- collection_config "rbs_collection.yaml"
7
- end
@@ -1,194 +0,0 @@
1
- ---
2
- sources:
3
- - type: git
4
- name: ruby/gem_rbs_collection
5
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
6
- remote: https://github.com/ruby/gem_rbs_collection.git
7
- repo_dir: gems
8
- path: ".gem_rbs_collection"
9
- gems:
10
- - name: actionmailer
11
- version: '7.0'
12
- source:
13
- type: git
14
- name: ruby/gem_rbs_collection
15
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
16
- remote: https://github.com/ruby/gem_rbs_collection.git
17
- repo_dir: gems
18
- - name: actionpack
19
- version: '6.0'
20
- source:
21
- type: git
22
- name: ruby/gem_rbs_collection
23
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
24
- remote: https://github.com/ruby/gem_rbs_collection.git
25
- repo_dir: gems
26
- - name: actionview
27
- version: '6.0'
28
- source:
29
- type: git
30
- name: ruby/gem_rbs_collection
31
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
32
- remote: https://github.com/ruby/gem_rbs_collection.git
33
- repo_dir: gems
34
- - name: activejob
35
- version: '6.0'
36
- source:
37
- type: git
38
- name: ruby/gem_rbs_collection
39
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
40
- remote: https://github.com/ruby/gem_rbs_collection.git
41
- repo_dir: gems
42
- - name: activemodel
43
- version: '7.0'
44
- source:
45
- type: git
46
- name: ruby/gem_rbs_collection
47
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
48
- remote: https://github.com/ruby/gem_rbs_collection.git
49
- repo_dir: gems
50
- - name: activerecord
51
- version: '7.0'
52
- source:
53
- type: git
54
- name: ruby/gem_rbs_collection
55
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
56
- remote: https://github.com/ruby/gem_rbs_collection.git
57
- repo_dir: gems
58
- - name: activestorage
59
- version: '6.1'
60
- source:
61
- type: git
62
- name: ruby/gem_rbs_collection
63
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
64
- remote: https://github.com/ruby/gem_rbs_collection.git
65
- repo_dir: gems
66
- - name: activesupport
67
- version: '7.0'
68
- source:
69
- type: git
70
- name: ruby/gem_rbs_collection
71
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
72
- remote: https://github.com/ruby/gem_rbs_collection.git
73
- repo_dir: gems
74
- - name: cgi
75
- version: '0'
76
- source:
77
- type: stdlib
78
- - name: concurrent-ruby
79
- version: '1.1'
80
- source:
81
- type: git
82
- name: ruby/gem_rbs_collection
83
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
84
- remote: https://github.com/ruby/gem_rbs_collection.git
85
- repo_dir: gems
86
- - name: date
87
- version: '0'
88
- source:
89
- type: stdlib
90
- - name: digest
91
- version: '0'
92
- source:
93
- type: stdlib
94
- - name: globalid
95
- version: '1.1'
96
- source:
97
- type: git
98
- name: ruby/gem_rbs_collection
99
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
100
- remote: https://github.com/ruby/gem_rbs_collection.git
101
- repo_dir: gems
102
- - name: i18n
103
- version: '1.10'
104
- source:
105
- type: git
106
- name: ruby/gem_rbs_collection
107
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
108
- remote: https://github.com/ruby/gem_rbs_collection.git
109
- repo_dir: gems
110
- - name: logger
111
- version: '0'
112
- source:
113
- type: stdlib
114
- - name: mail
115
- version: '2.8'
116
- source:
117
- type: git
118
- name: ruby/gem_rbs_collection
119
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
120
- remote: https://github.com/ruby/gem_rbs_collection.git
121
- repo_dir: gems
122
- - name: minitest
123
- version: '0'
124
- source:
125
- type: stdlib
126
- - name: monitor
127
- version: '0'
128
- source:
129
- type: stdlib
130
- - name: mutex_m
131
- version: '0'
132
- source:
133
- type: stdlib
134
- - name: nokogiri
135
- version: '1.11'
136
- source:
137
- type: git
138
- name: ruby/gem_rbs_collection
139
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
140
- remote: https://github.com/ruby/gem_rbs_collection.git
141
- repo_dir: gems
142
- - name: rack
143
- version: '2.2'
144
- source:
145
- type: git
146
- name: ruby/gem_rbs_collection
147
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
148
- remote: https://github.com/ruby/gem_rbs_collection.git
149
- repo_dir: gems
150
- - name: rails-dom-testing
151
- version: '2.0'
152
- source:
153
- type: git
154
- name: ruby/gem_rbs_collection
155
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
156
- remote: https://github.com/ruby/gem_rbs_collection.git
157
- repo_dir: gems
158
- - name: railties
159
- version: '6.0'
160
- source:
161
- type: git
162
- name: ruby/gem_rbs_collection
163
- revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
164
- remote: https://github.com/ruby/gem_rbs_collection.git
165
- repo_dir: gems
166
- - name: securerandom
167
- version: '0'
168
- source:
169
- type: stdlib
170
- - name: singleton
171
- version: '0'
172
- source:
173
- type: stdlib
174
- - name: tempfile
175
- version: '0'
176
- source:
177
- type: stdlib
178
- - name: time
179
- version: '0'
180
- source:
181
- type: stdlib
182
- - name: timeout
183
- version: '0'
184
- source:
185
- type: stdlib
186
- - name: tsort
187
- version: '0'
188
- source:
189
- type: stdlib
190
- - name: uri
191
- version: '0'
192
- source:
193
- type: stdlib
194
- gemfile_lock_path: Gemfile.lock
data/rbs_collection.yaml DELETED
@@ -1,19 +0,0 @@
1
- sources:
2
- - type: git
3
- name: ruby/gem_rbs_collection
4
- remote: https://github.com/ruby/gem_rbs_collection.git
5
- revision: main
6
- repo_dir: gems
7
-
8
- path: .gem_rbs_collection
9
-
10
- gems:
11
- - name: rbs
12
- ignore: true
13
- - name: steep
14
- ignore: true
15
- - name: tanshuku
16
- ignore: true
17
-
18
- - name: digest
19
- - name: securerandom
@@ -1,5 +0,0 @@
1
- module Tanshuku
2
- class UrlsController < ActionController::API
3
- def show: -> void
4
- end
5
- end
@@ -1,114 +0,0 @@
1
- # cf. https://github.com/pocke/rbs_rails
2
- module Tanshuku
3
- class Url < ActiveRecord::Base
4
- class ActiveRecord_Relation < ActiveRecord::Relation
5
- include _ActiveRecord_Relation[Tanshuku::Url, Integer]
6
- include Enumerable[Tanshuku::Url]
7
- end
8
-
9
- extend _ActiveRecord_Relation_ClassMethods[Tanshuku::Url, ActiveRecord_Relation, Integer]
10
-
11
- DEFAULT_NAMESPACE: String
12
-
13
- module GeneratedAttributeMethods
14
- attr_accessor id (): Integer?
15
- def id?: () -> bool
16
- def id_changed?: () -> bool
17
- def id_change: () -> [Integer?, Integer?]
18
- def id_will_change!: () -> void
19
- def id_was: () -> Integer?
20
- def id_previously_changed?: () -> bool
21
- def id_previous_change: () -> [Integer?, Integer?]?
22
- def id_previously_was: () -> Integer?
23
- def id_before_last_save: () -> Integer?
24
- def id_change_to_be_saved: () -> [Integer?, Integer?]?
25
- def id_in_database: () -> Integer?
26
- def saved_change_to_id: () -> [Integer?, Integer?]?
27
- def saved_change_to_id?: () -> bool
28
- def will_save_change_to_id?: () -> bool
29
- def restore_id!: () -> void
30
- def clear_id_change: () -> void
31
-
32
- attr_accessor url (): String?
33
- def url?: () -> bool
34
- def url_changed?: () -> bool
35
- def url_change: () -> [String?, String?]
36
- def url_will_change!: () -> void
37
- def url_was: () -> String?
38
- def url_previously_changed?: () -> bool
39
- def url_previous_change: () -> [String?, String?]?
40
- def url_previously_was: () -> String?
41
- def url_before_last_save: () -> String?
42
- def url_change_to_be_saved: () -> [String?, String?]?
43
- def url_in_database: () -> String?
44
- def saved_change_to_url: () -> [String?, String?]?
45
- def saved_change_to_url?: () -> bool
46
- def will_save_change_to_url?: () -> bool
47
- def restore_url!: () -> void
48
- def clear_url_change: () -> void
49
-
50
- attr_accessor hashed_url (): String?
51
- def hashed_url?: () -> bool
52
- def hashed_url_changed?: () -> bool
53
- def hashed_url_change: () -> [String?, String?]
54
- def hashed_url_will_change!: () -> void
55
- def hashed_url_was: () -> String?
56
- def hashed_url_previously_changed?: () -> bool
57
- def hashed_url_previous_change: () -> [String?, String?]?
58
- def hashed_url_previously_was: () -> String?
59
- def hashed_url_before_last_save: () -> String?
60
- def hashed_url_change_to_be_saved: () -> [String?, String?]?
61
- def hashed_url_in_database: () -> String?
62
- def saved_change_to_hashed_url: () -> [String?, String?]?
63
- def saved_change_to_hashed_url?: () -> bool
64
- def will_save_change_to_hashed_url?: () -> bool
65
- def restore_hashed_url!: () -> void
66
- def clear_hashed_url_change: () -> void
67
-
68
- attr_accessor key (): String?
69
- def key?: () -> bool
70
- def key_changed?: () -> bool
71
- def key_change: () -> [String?, String?]
72
- def key_will_change!: () -> void
73
- def key_was: () -> String?
74
- def key_previously_changed?: () -> bool
75
- def key_previous_change: () -> [String?, String?]?
76
- def key_previously_was: () -> String?
77
- def key_before_last_save: () -> String?
78
- def key_change_to_be_saved: () -> [String?, String?]?
79
- def key_in_database: () -> String?
80
- def saved_change_to_key: () -> [String?, String?]?
81
- def saved_change_to_key?: () -> bool
82
- def will_save_change_to_key?: () -> bool
83
- def restore_key!: () -> void
84
- def clear_key_change: () -> void
85
-
86
- attr_accessor created_at (): ActiveSupport::TimeWithZone?
87
- def created_at?: () -> bool
88
- def created_at_changed?: () -> bool
89
- def created_at_change: () -> [ActiveSupport::TimeWithZone?, ActiveSupport::TimeWithZone?]
90
- def created_at_will_change!: () -> void
91
- def created_at_was: () -> ActiveSupport::TimeWithZone?
92
- def created_at_previously_changed?: () -> bool
93
- def created_at_previous_change: () -> [ActiveSupport::TimeWithZone?, ActiveSupport::TimeWithZone?]?
94
- def created_at_previously_was: () -> ActiveSupport::TimeWithZone?
95
- def created_at_before_last_save: () -> ActiveSupport::TimeWithZone?
96
- def created_at_change_to_be_saved: () -> [ActiveSupport::TimeWithZone?, ActiveSupport::TimeWithZone?]?
97
- def created_at_in_database: () -> ActiveSupport::TimeWithZone?
98
- def saved_change_to_created_at: () -> [ActiveSupport::TimeWithZone?, ActiveSupport::TimeWithZone?]?
99
- def saved_change_to_created_at?: () -> bool
100
- def will_save_change_to_created_at?: () -> bool
101
- def restore_created_at!: () -> void
102
- def clear_created_at_change: () -> void
103
- end
104
- include GeneratedAttributeMethods
105
-
106
- def self.shorten: (String original_url, ?namespace: String, ?url_options: Hash[String | Symbol, untyped]) -> String
107
- def self.find_by_url: (String url, ?namespace: String) -> Tanshuku::Url?
108
- def self.normalize_url: (String url) -> String
109
- def self.hash_url: (String url, ?namespace: String) -> String
110
- def self.generate_key: -> String
111
- def self.report_exception: (exception: Exception, original_url: String) -> void
112
- def shortened_url: (?Hash[String | Symbol, untyped] url_options) -> String
113
- end
114
- end
@@ -1,2 +0,0 @@
1
- class CreateTanshukuUrls < ActiveRecord::Migration::Compatibility::V7_0
2
- end
@@ -1,4 +0,0 @@
1
- module Tanshuku
2
- class InstallGenerator < Rails::Generators::Base
3
- end
4
- end
@@ -1,42 +0,0 @@
1
- module Tanshuku
2
- class Configuration
3
- interface _UrlHasher
4
- def call: (String url, namespace: String) -> String
5
- end
6
-
7
- interface _KeyGenerator
8
- def call: -> String
9
- end
10
-
11
- interface _ExceptionReporter
12
- def call: (exception: Exception, original_url: String) -> void
13
- end
14
-
15
- extend ActiveModel::Attributes::ClassMethods
16
-
17
- @mutex: Thread::Mutex
18
-
19
- attr_accessor default_url_options (): Hash[String | Symbol, untyped]
20
- attr_accessor max_url_length (): Integer
21
- attr_accessor url_pattern (): Regexp
22
- attr_accessor key_length (): Integer
23
- attr_accessor url_hasher (): _UrlHasher
24
- attr_accessor key_generator (): _KeyGenerator
25
- attr_accessor exception_reporter (): _ExceptionReporter
26
-
27
- def initialize: (*bot noname) -> void
28
- def configure: { (Configuration) -> void } -> void
29
-
30
- module DefaultUrlHasher
31
- extend _UrlHasher
32
- end
33
-
34
- module DefaultKeyGenerator
35
- extend _KeyGenerator
36
- end
37
-
38
- module DefaultExceptionReporter
39
- extend _ExceptionReporter
40
- end
41
- end
42
- end
@@ -1,4 +0,0 @@
1
- module Tanshuku
2
- class Engine < Rails::Engine
3
- end
4
- end
@@ -1,3 +0,0 @@
1
- module Tanshuku
2
- VERSION: String
3
- end
data/sig/lib/tanshuku.rbs DELETED
@@ -1,6 +0,0 @@
1
- module Tanshuku
2
- self.@config: Configuration
3
-
4
- def self.config: -> Configuration
5
- def self.configure: { (Configuration config) -> void } -> void
6
- end