shortener 0.8.1 → 0.8.2

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: 9a8820cdee8a530e85514c1c8b3c3749216c0cd4703c31c2307e96a4897eba25
4
- data.tar.gz: 185560e234f5c00d49a4e32ed4c3a3bae2c69c33d58b827c414cd5b24c7a4f66
3
+ metadata.gz: a65ebf87f18746199fa76ac0a91f3365d0c34b9c969f897c25422370a676355b
4
+ data.tar.gz: 8a06527bce6d9f10805d2a97525b04dc631ee1c9115cc3e016bb5263307269a3
5
5
  SHA512:
6
- metadata.gz: d1a48b44d3938a2436116251515250a892a3aefd08e1a0c75f9abdaa16e050404e6cc43780336405dc8b447595199e7a8978aa915d0d68dc2d000090d16c62e6
7
- data.tar.gz: 4e43a6b1f6189a779769649aae7bb37c50aa00433fbc61ad0d159031eb545b8142cb1eb454be1882f33800d4ac4c9c35fd5c89eafb78213aeba955f1cd118c8a
6
+ metadata.gz: 62ec7fe6fc1a26fd89804c967a00fffa9d7e9235ecb10d1b338dd188ca5f12bcf964ac983e2bac597b1a97a2b5195002060c81db280355701967a6d1b324bb60
7
+ data.tar.gz: 427b8118350ff106e97828caf7ce41433ae1dcc69d67c902e6e871555613e64bd4a5256709a22f3bf4d95c587cc96f43235bd38f6eb91cb17b454a24039337d8
@@ -1,13 +1,12 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.2.10
4
+ - 2.2
5
5
  - 2.3
6
6
  - 2.4
7
7
  - 2.5
8
-
9
- matrix:
10
- fast_finish: true
8
+ - 2.6
9
+ - 2.7
11
10
 
12
11
  gemfile:
13
12
  - gemfiles/rails_4.gemfile
@@ -15,3 +14,19 @@ gemfile:
15
14
  - gemfiles/rails_5.1.gemfile
16
15
  - gemfiles/rails_5.2.gemfile
17
16
  - gemfiles/rails_6.0.gemfile
17
+
18
+ jobs:
19
+ fast_finish: true
20
+ exclude:
21
+ - rvm: 2.6
22
+ gemfile: gemfiles/rails_4.gemfile
23
+ - rvm: 2.7
24
+ gemfile: gemfiles/rails_4.gemfile
25
+ - rvm: 2.2
26
+ gemfile: gemfiles/rails_5.2.gemfile
27
+ - rvm: 2.2
28
+ gemfile: gemfiles/rails_6.0.gemfile
29
+ - rvm: 2.3
30
+ gemfile: gemfiles/rails_6.0.gemfile
31
+ - rvm: 2.4
32
+ gemfile: gemfiles/rails_6.0.gemfile
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify any dependencies in the gemspec
4
4
  gemspec
@@ -1,5 +1,6 @@
1
- {<img src="https://secure.travis-ci.org/jpmcgrath/shortener.png?branch=master" alt="Build Status" />}[http://travis-ci.org/jpmcgrath/shortener] {<img src="https://codeclimate.com/github/jpmcgrath/shortener/badges/gpa.svg" />}[https://codeclimate.com/github/jpmcgrath/shortener]
2
- {<img src="https://badge.fury.io/rb/shortener.png" alt="Gem version" />}[http://badge.fury.io/rb/shortener]
1
+ {<img src="https://secure.travis-ci.org/jpmcgrath/shortener.svg?branch=master" alt="Build Status" />}[http://travis-ci.org/jpmcgrath/shortener]
2
+ {<img src="https://codeclimate.com/github/jpmcgrath/shortener/badges/gpa.svg" />}[https://codeclimate.com/github/jpmcgrath/shortener]
3
+ {<img src="https://badge.fury.io/rb/shortener.svg" alt="Gem version" />}[http://badge.fury.io/rb/shortener]
3
4
 
4
5
  = Shortener
5
6
 
@@ -62,12 +63,6 @@ migration:
62
63
  * The link records a count of how many times it has been “un-shortened”;
63
64
  * The link can be associated with a user, this allows for stats of the link usage for a particular user and other interesting things;
64
65
 
65
- === Future improvements:
66
-
67
- * There has not been an attempt to remove ambiguous characters (i.e. 1 l and capital i, or 0 and O etc.) from the unique key generated for the link. This means people might copy the link incorrectly if copying the link by hand;
68
- * The system could pre-generate unique keys in advance, avoiding the database penalty when checking that a newly generated key is unique;
69
- * The system could store/cache the shortened URL if the url is to be continually rendered;
70
-
71
66
  == Installation
72
67
 
73
68
  Shortener is compatible with Rails v3, v4, v5, & v6. To install, add to your Gemfile:
@@ -101,11 +96,16 @@ By default, Shortener will generate unique keys using numbers and lowercase a-z.
101
96
  the upper and lower case charset, by including the following:
102
97
 
103
98
  Shortener.charset = :alphanumcase
104
-
99
+
105
100
  If you want to use a custom charset, you can create your own combination by creating an array of possible values, such as allowing underscore and dashes:
106
101
 
107
102
  Shortener.charset = ("a".."z").to_a + (0..9).to_a + ["-", "_"]
108
103
 
104
+ By default, <b>Shortener assumes URLs to be valid web URLs</b> and normalizes them in an effort to make sure there are no duplicate records generated for effectively same URLs with differences of only non-effective slash etc.
105
+ You can control this option if it interferes for any of your logic. One common case is for mobile app links or universal links where normalization can corrupt the URLs of form <tt>appname://some_route</tt>
106
+
107
+ Shortener.auto_clean_url = true
108
+
109
109
  == Usage
110
110
 
111
111
  To generate a Shortened URL object for the URL "http://example.com" within your controller / models do the following:
@@ -146,7 +146,7 @@ And to access those URLs:
146
146
 
147
147
  === Shortened URLs with custom unique key
148
148
 
149
- You can pass in your own key when generating a shortened URL. This should be unique.
149
+ You can pass in your own key when generating a shortened URL. This should be unique.
150
150
 
151
151
  *Important:* Custom keys can't contain characters other than those defined in *Shortener.charset*. Default is numbers and lowercase a-z (See *Configuration*).
152
152
 
@@ -52,7 +52,8 @@ class Shortener::ShortenedUrl < ActiveRecord::Base
52
52
  scope = owner ? owner.shortened_urls : self
53
53
  creation_method = fresh ? 'create' : 'first_or_create'
54
54
 
55
- scope.where(url: clean_url(destination_url), category: category).send(
55
+ url_to_save = Shortener.auto_clean_url ? clean_url(destination_url) : destination_url
56
+ scope.where(url: url_to_save, category: category).send(
56
57
  creation_method,
57
58
  custom_key: custom_key,
58
59
  expires_at: expires_at
@@ -41,6 +41,10 @@ module Shortener
41
41
  mattr_accessor :persist_retries
42
42
  self.persist_retries = 3
43
43
 
44
+ # auto_clean_url - controls url cleaning mechanism, set it to false to disable
45
+ mattr_accessor :auto_clean_url
46
+ self.auto_clean_url = true
47
+
44
48
  def self.key_chars
45
49
  charset.is_a?(Symbol) ? CHARSETS[charset] : charset
46
50
  end
@@ -1,3 +1,3 @@
1
1
  module Shortener
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  end
@@ -138,13 +138,17 @@ describe Shortener::ShortenedUrlsController, type: :controller do
138
138
  Shortener.charset = ("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a + ["-", "_"]
139
139
  end
140
140
 
141
+ after do
142
+ Shortener.charset = :alphanum
143
+ end
144
+
141
145
  context 'key with valid characters' do
142
146
  let(:key) { "cust-Key_123" }
143
147
  let(:custom_url) { Shortener::ShortenedUrl.generate(Faker::Internet.url, custom_key: key) }
144
148
  it 'allows if in custom charset' do
145
149
  expect(custom_url.unique_key).to eq key
146
- end
147
- end
150
+ end
151
+ end
148
152
  end
149
153
 
150
154
  context 'expired code' do
@@ -177,8 +177,26 @@ describe Shortener::ShortenedUrl, type: :model do
177
177
  it 'finds the shortened url from slashless oath' do
178
178
  expect(Shortener::ShortenedUrl.generate!(path)).to eq existing_shortened_url
179
179
  end
180
- it "should look up exsiting URL" do
181
- expect(Shortener::ShortenedUrl.generate!("/#{path}")).to eq existing_shortened_url
180
+
181
+ context 'with auto_clean_url enabled by default' do
182
+ it "looks up existing cleaned URL" do
183
+ expect(Shortener::ShortenedUrl.generate!("/#{path}")).to eq existing_shortened_url
184
+ end
185
+ end
186
+
187
+ context 'with auto_clean_url disabled' do
188
+ around do |spec|
189
+ tries = Shortener.auto_clean_url
190
+ Shortener.auto_clean_url = false
191
+ spec.run
192
+ Shortener.auto_clean_url = tries
193
+ end
194
+
195
+ it "does not look up existing cleaned URL" do
196
+ shortened_url = Shortener::ShortenedUrl.generate!("/#{path}")
197
+ expect(shortened_url).not_to eq existing_shortened_url
198
+ expect(shortened_url.url).to eq "/#{path}"
199
+ end
182
200
  end
183
201
  end
184
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James P. McGrath
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-26 00:00:00.000000000 Z
12
+ date: 2020-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: voight_kampff