tanshuku 0.0.8 → 0.0.10

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: c4b9a3b20b2baf4c09ad35c5e10d00419ec7e3492f885b3cceb9cc129355f722
4
- data.tar.gz: f66396318dcb615cef25136c8e6206cf3b857ea4907cb0fb45f1195f4e53caf5
3
+ metadata.gz: a8126e6ece1367088566945159c232716b022d71d30dcf33ca6689c5433a9850
4
+ data.tar.gz: b9cfd16613a396e9e2ab36811ca41c9a98a80b6f045f3bd3a3fb1938dc9b69e3
5
5
  SHA512:
6
- metadata.gz: 02f976e4e5b3d24cbdb867eba134387f74b4050b65238d26a2307308b12ce55413fbe42fe95bfff68e3b25deca790eed20852ee50ea2069be2cbd0c8430aab38
7
- data.tar.gz: efaf9a395bab9c57a3cb985cc93f699c5f5c39dd8c776d23ebae71531b2a398044dd1c15c452bbbdeb988961b492179aa6fc821910dd71a65d03197182f0e80f
6
+ metadata.gz: 372e5a161e2d4ece17641df2978c50defc764eb8db53114e10469da15ddce2a1b52d25d452299c240d384b39df50bd705153246cb5201a4ffb5d6988dcf077c6
7
+ data.tar.gz: c6fe73ec40e14f78e9af4b2838f2b895970ea3ada9df65932125db326358eebfc52d62cace498027fb5cf2df589dbe34ca63852610c5dd15e486155129c92e90
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
3
+ require "bundler/setup"
4
4
 
5
- require "rubocop/rake_task"
5
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
6
+ load "rails/tasks/engine.rake"
6
7
 
7
- RuboCop::RakeTask.new
8
+ load "rails/tasks/statistics.rake"
8
9
 
9
- task default: :rubocop
10
+ require "bundler/gem_tasks"
@@ -9,34 +9,41 @@ require "securerandom"
9
9
  module Tanshuku
10
10
  class Url < ActiveRecord::Base
11
11
  MAX_URL_LENGTH = 10_000
12
- URL_PATTERN = %r{\A(?:https?:/)?/\w+}
12
+ URL_PATTERN = %r{\A(?:https?://\w+|/)}
13
13
  KEY_LENGTH = 20
14
14
 
15
15
  validates :url, :hashed_url, :key, presence: true
16
16
  validates :url, length: { maximum: MAX_URL_LENGTH }
17
- validates :url, format: { with: URL_PATTERN }
17
+ validates :url, format: { with: URL_PATTERN }, allow_blank: true
18
18
 
19
19
  # Don't validate uniqueness of unique attributes. Raise ActiveRecord::RecordNotUnique instead if the attributes get
20
20
  # duplicated. Then rescue the exception and try to retry.
21
21
  # validates :url, :hashed_url, :key, uniqueness: true
22
22
 
23
- def self.shorten(original_url, retries: 0)
23
+ def self.shorten(original_url)
24
+ raise ArgumentError, "original_url should be present" unless original_url
25
+
24
26
  url = normalize_url(original_url)
27
+ retries = 0
25
28
 
26
- transaction do
27
- record =
28
- create_or_find_by!(hashed_url: hash_url(url)) do |r|
29
- r.attributes = { url:, key: generate_key }
30
- end
29
+ begin
30
+ transaction do
31
+ record =
32
+ create_or_find_by!(hashed_url: hash_url(url)) do |r|
33
+ r.attributes = { url:, key: generate_key }
34
+ end
31
35
 
32
- record.shortened_url
33
- end
34
- rescue ActiveRecord::RecordNotUnique => e
35
- if retries < 10
36
- shorten(url, retries: retries + 1)
37
- else
38
- report_exception(exception: e, original_url:)
39
- original_url
36
+ record.shortened_url
37
+ end
38
+ # ActiveRecord::RecordNotFound is raised when the key is duplicated.
39
+ rescue ActiveRecord::RecordNotFound => e
40
+ if retries < 10
41
+ retries += 1
42
+ retry
43
+ else
44
+ report_exception(exception: e, original_url:)
45
+ original_url
46
+ end
40
47
  end
41
48
  rescue StandardError => e
42
49
  report_exception(exception: e, original_url:)
@@ -3,5 +3,9 @@
3
3
  module Tanshuku
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace Tanshuku
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec
9
+ end
6
10
  end
7
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.10"
5
5
  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.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - kg8m
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,92 +38,9 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '7'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-performance
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop-rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- description: Tanshuku is a Rails engine for shortening URLs. Tanshuku generates a
126
- shortened URL per a normalized original URL.
41
+ description: Tanshuku is a simple and performance aware Rails engine for shortening
42
+ URLs. Tanshuku generates a shortened URL per a normalized original URL.Tanshuku
43
+ redirects from a shortened URL to its correspond original URL.
127
44
  email:
128
45
  - takumi.kagiyama@gmail.com
129
46
  executables: []
@@ -167,5 +84,5 @@ requirements: []
167
84
  rubygems_version: 3.4.1
168
85
  signing_key:
169
86
  specification_version: 4
170
- summary: Tanshuku is a Rails engine for shortening URLs.
87
+ summary: Tanshuku is a simple and performance aware Rails engine for shortening URLs.
171
88
  test_files: []