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 +4 -4
- data/Rakefile +5 -4
- data/app/models/tanshuku/url.rb +23 -16
- data/lib/tanshuku/engine.rb +4 -0
- data/lib/tanshuku/version.rb +1 -1
- metadata +7 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8126e6ece1367088566945159c232716b022d71d30dcf33ca6689c5433a9850
|
4
|
+
data.tar.gz: b9cfd16613a396e9e2ab36811ca41c9a98a80b6f045f3bd3a3fb1938dc9b69e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
3
|
+
require "bundler/setup"
|
4
4
|
|
5
|
-
|
5
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
6
|
+
load "rails/tasks/engine.rake"
|
6
7
|
|
7
|
-
|
8
|
+
load "rails/tasks/statistics.rake"
|
8
9
|
|
9
|
-
|
10
|
+
require "bundler/gem_tasks"
|
data/app/models/tanshuku/url.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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:)
|
data/lib/tanshuku/engine.rb
CHANGED
data/lib/tanshuku/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kg8m
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
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
|
-
|
42
|
-
|
43
|
-
|
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: []
|