tanshuku 1.0.1 → 2.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: 751d1c1f90f9971762a9a7ae487b8323fbfe4d9f6993cc94d9d8e1498c36f8d0
4
- data.tar.gz: abb9053bcf5f52ecaa831d8a57fde2e36e87f5e5ed32588778ed8f43f7b8ad02
3
+ metadata.gz: 12ed0c4f9a99b9b6e2c988a8fe327cc491420b9586c3128dd6e2493f46819b0a
4
+ data.tar.gz: a566c0f82f98f54301b3ab91ce23dc09629ba2e5de79970b06b62ac13d54cf10
5
5
  SHA512:
6
- metadata.gz: bf8a091f25271f333101f5be219c96aa45d23ccc3bf30991799430cbf6219a11271dbc4621b5763deb825cfa0d3f9db13a5d96ecc052c38b3b9d47e408c0f61c
7
- data.tar.gz: a49d215042a71564d34ea5e9ce5450b0bd72e8351d7a9d05d3219502045b4cccb5ecd8eff9bba07e4c7a03a70133e83855320b85f9ac2531351898b4b528b668
6
+ metadata.gz: 28d39d2e039b8916441f4bca51c130374002c416d9afd08836166ea354370bbe341be9df7b552e023e5f03c6abc08071493434b3bbb62df862391c55d7f82349
7
+ data.tar.gz: 0c7e3337b95a5e647e8cd44d2a61df7070ac9897537d047dd10aaff243cd227f3622e68f549152bfc94eaa9f6e34bd6732185fc4812c749e477550bc0ca6303b
data/README.md CHANGED
@@ -1,9 +1,3 @@
1
- [![RubyGems.org](https://img.shields.io/badge/RubyGems.org-Tanshuku%20v1-red)](https://rubygems.org/gems/tanshuku/versions/1.0.0)
2
- [![Ruby 2.5+](https://img.shields.io/badge/Ruby-2.5+-red)](https://www.ruby-lang.org)
3
- [![Rails 5.1+](https://img.shields.io/badge/Rails-5.1+-red)](https://rubyonrails.org/)
4
- [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
- [![Checks](https://github.com/kg8m/tanshuku/actions/workflows/checks.yml/badge.svg?branch=1-0-stable)](https://github.com/kg8m/tanshuku/blob/1-0-stable/.github/workflows/checks.yml)
6
-
7
1
  # Tanshuku
8
2
 
9
3
  Tanshuku is a simple and small Rails engine that makes it easier to shorten URLs.
@@ -26,11 +26,10 @@ 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 } }
29
30
  validates :url, format: { with: proc { Tanshuku.config.url_pattern } }, allow_blank: true
30
31
 
31
32
  # Don’t validate uniqueness of unique attributes. Raise ActiveRecord::RecordNotUnique instead if the attributes get
32
- validate :validates_length_of_url
33
-
34
33
  # duplicated. Then rescue the exception and try to retry.
35
34
  # validates :url, :hashed_url, :key, uniqueness: true
36
35
 
@@ -104,15 +103,6 @@ module Tanshuku
104
103
  original_url
105
104
  end
106
105
 
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
-
116
106
  # Finds a {Tanshuku::Url} record by a non-shortened URL.
117
107
  #
118
108
  # @param url [String] A non-shortened URL.
@@ -185,14 +175,6 @@ module Tanshuku
185
175
 
186
176
  Tanshuku::Engine.routes.url_for(url_options)
187
177
  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
196
178
  end
197
179
  # rubocop:enable Rails/ApplicationRecord
198
180
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CreateTanshukuUrls < ActiveRecord::Migration[5.1]
3
+ class CreateTanshukuUrls < ActiveRecord::Migration[6.0]
4
4
  def change
5
5
  create_table :tanshuku_urls do |t|
6
6
  t.text :url, null: false
@@ -42,84 +42,7 @@ module Tanshuku
42
42
  end
43
43
  end
44
44
 
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
107
-
108
- # @!attribute [rw] default_url_options
109
- # Default URL options for Rails’ +url_for+. Defaults to +{}+.
110
- #
111
- # @return [Hash]
112
- # @return [void] If you set an invalid object.
113
- #
114
- # @note
115
- # The example below means that the configured host and protocol are used. Shortened URLs will be like
116
- # +https://example.com/t/abcdefghij0123456789+.
117
- #
118
- # @example
119
- # # config/initializers/tanshuku.rb
120
- # Tanshuku.configure do |config|
121
- # config.default_url_options = { host: "example.com", protocol: :https }
122
- # end
45
+ include ActiveModel::Attributes
123
46
  attribute :default_url_options, default: {}
124
47
 
125
48
  # @!attribute [rw] max_url_length
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- VERSION = "1.0.1"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/tanshuku.rb CHANGED
@@ -15,9 +15,9 @@ 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 ThreadSafety/InstanceVariableInClassMethod
19
19
  @config ||= Configuration.new
20
- # rubocop:enable ThreadSafety/ClassInstanceVariable
20
+ # rubocop:enable ThreadSafety/InstanceVariableInClassMethod
21
21
  end
22
22
 
23
23
  # Configures Tanshuku.
@@ -21,9 +21,7 @@ class CheckAll
21
21
  end
22
22
 
23
23
  def call
24
- # rubocop:disable ThreadSafety/NewThread
25
24
  TASKNAMES.map { |taskname| Thread.new(taskname, &executor) }.each(&:join)
26
- # rubocop:enable ThreadSafety/NewThread
27
25
  output_result
28
26
  end
29
27
 
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: 1.0.1
4
+ version: 2.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: 2024-11-16 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
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '6.0'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '7.0'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '5.1'
43
+ version: '6.0'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '7.0'
@@ -85,17 +85,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '2.5'
88
+ version: '3.0'
89
89
  - - "<"
90
90
  - !ruby/object:Gem::Version
91
- version: '3.0'
91
+ version: '3.1'
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.1.6
98
+ rubygems_version: 3.2.33
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Tanshuku is a simple and performance aware Rails engine for shortening URLs.