tanshuku 1.0.0 → 2.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: 92f985a414af971db170f5ce9a171469af6901f47feb4345a3b8ad96d256854e
4
- data.tar.gz: 64a303579eb92b6748332d1f15259d4de493c11d32d572fd98a539269f3fffda
3
+ metadata.gz: 12ed0c4f9a99b9b6e2c988a8fe327cc491420b9586c3128dd6e2493f46819b0a
4
+ data.tar.gz: a566c0f82f98f54301b3ab91ce23dc09629ba2e5de79970b06b62ac13d54cf10
5
5
  SHA512:
6
- metadata.gz: e5cd414ab9fcebdb55fa961744ac339d668466200972dfd8e0cc0b46a567f183fc00541cb3ffe784173d1eda3fa63f7c2c796eeee5488b7e396d9fb8dd98ff3e
7
- data.tar.gz: f5f1e7a1d50cb26f2e61973903e708e255e2bb76248c6e7e7d14b74dd55a6fbb9a13a842dc2f8bf0f33cc7aae70bf33b500e5a337c8fc3af910a60ce108b8f88
6
+ metadata.gz: 28d39d2e039b8916441f4bca51c130374002c416d9afd08836166ea354370bbe341be9df7b552e023e5f03c6abc08071493434b3bbb62df862391c55d7f82349
7
+ data.tar.gz: 0c7e3337b95a5e647e8cd44d2a61df7070ac9897537d047dd10aaff243cd227f3622e68f549152bfc94eaa9f6e34bd6732185fc4812c749e477550bc0ca6303b
@@ -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.0"
4
+ VERSION = "2.0.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanshuku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kg8m
@@ -30,20 +30,20 @@ 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
- version: '6.0'
36
+ version: '7.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
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
- version: '6.0'
46
+ version: '7.0'
47
47
  description: Tanshuku is a simple and performance aware Rails engine for shortening
48
48
  URLs. Tanshuku generates a shortened URL per a normalized original URL. Tanshuku
49
49
  redirects from a shortened URL to its corresponding original URL.
@@ -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.