tanshuku 0.0.7 → 0.0.9

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: 38d3ba69ba0a6432273e4fee3756e8d076e3bdbc72bcc46da8a94f5265b25fc1
4
- data.tar.gz: 70c68e951bdf934317bec5ab150e439eaf4998bc4dfb5e55c6c4632ce0d80cdf
3
+ metadata.gz: aa7ab0b4cb36fafbd7747af1bff6592c5b775b9602bc664d84dbc195daa0ed3b
4
+ data.tar.gz: 1826f56d1be47b0925d2b5d05c5992f8218f499e02f6c049612e44f09e9a577b
5
5
  SHA512:
6
- metadata.gz: ae0b395952fb40de5d9afa799f61673f908ed3b72e31fb91804be8b9c9b804eaf9cc8d4d00680b9db27280b040879c920f15f54be8dd037dc5207761c12972f4
7
- data.tar.gz: 60c89143f88f3bccaa7a3197ba5ff4231d8ac57021beef2ee913c853c7440efa9a89d8b0e8dc1393b8d5c19e8f388449f8149aeed3af3777057d88b63856f20f
6
+ metadata.gz: 208cd3049977df30d0bd0757f5575414da55464b343f77f31e1d3195f8fd4377718b3d3c3067e0df6ff43fa198ef2c37666ffe9201e8242af465c90fc1108ead
7
+ data.tar.gz: 65d877e047853c97baef247b3508fe5a181d9ecf8d0696be491d6caf389bc9252ba155b6b465abe843c184e28300bca36c4b4a22695dfd5a04bc31b6a3b80bcf
@@ -9,7 +9,7 @@ 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
@@ -21,14 +21,18 @@ module Tanshuku
21
21
  # validates :url, :hashed_url, :key, uniqueness: true
22
22
 
23
23
  def self.shorten(original_url, retries: 0)
24
+ raise ArgumentError, "original_url should be present" unless original_url
25
+
24
26
  url = normalize_url(original_url)
25
27
 
26
- record =
27
- create_or_find_by!(hashed_url: hash_url(url)) do |r|
28
- r.attributes = { url:, key: generate_key }
29
- end
28
+ transaction do
29
+ record =
30
+ create_or_find_by!(hashed_url: hash_url(url)) do |r|
31
+ r.attributes = { url:, key: generate_key }
32
+ end
30
33
 
31
- record.shortened_url
34
+ record.shortened_url
35
+ end
32
36
  rescue ActiveRecord::RecordNotUnique => e
33
37
  if retries < 10
34
38
  shorten(url, retries: retries + 1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tanshuku
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.9"
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.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - kg8m
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-22 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable