ruby-short_url 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubocop.yml +20 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +14 -0
- data/.travis.yml +5 -5
- data/Gemfile +10 -0
- data/LICENSE +1 -1
- data/README.md +13 -9
- data/Rakefile +6 -4
- data/bin/console +4 -3
- data/lib/ruby/short_url/encoder.rb +6 -2
- data/lib/ruby/short_url/version.rb +3 -1
- data/lib/ruby-short_url.rb +2 -0
- data/ruby-short_url.gemspec +11 -16
- metadata +8 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0d1ec6226599a832509efde0026d2e617ac9e8b624afdf4659e9b6b5e22c695d
|
4
|
+
data.tar.gz: 1ebc6a2ab572cd422f7cd72ec401cedb3355d6bbc79dd5432337b742758ac18e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95b0b18faaa8dd3b01e59d4aa26efab02195c75c049298eb253a8f569ca10939a12789e6c84584d8e461d7c06efac6b87c6802cdc56dc9ce7d0ac6a0922171e
|
7
|
+
data.tar.gz: 345d2afce842c154cee3847b08aa62a0a86775537c494f7078f478b2105cde2b93641c8072bb51110e6d7a1d4fc75ee1f0bd02fa23409e2d81bde33e01dc775f
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
on: [pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
name: rubocop
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@v2
|
9
|
+
- name: Set up Ruby
|
10
|
+
uses: actions/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: 2.6
|
13
|
+
- run: bundle install
|
14
|
+
- uses: actions/cache@v1
|
15
|
+
with:
|
16
|
+
path: vendor/bundle
|
17
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
18
|
+
restore-keys: |
|
19
|
+
${{ runner.os }}-gems-
|
20
|
+
- run: bundle exec rubocop
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
Style/HashTransformKeys:
|
6
|
+
Enabled: true
|
7
|
+
Style/HashTransformValues:
|
8
|
+
Enabled: true
|
9
|
+
Layout/LineLength:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Enabled: false
|
13
|
+
Naming/FileName:
|
14
|
+
Enabled: false
|
15
|
+
Style/NumericPredicate:
|
16
|
+
EnforcedStyle: comparison
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-03-09 23:12:09 +0900 using RuboCop version 0.80.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 12
|
10
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
11
|
+
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
|
12
|
+
Naming/MethodParameterName:
|
13
|
+
Exclude:
|
14
|
+
- 'lib/ruby/short_url/encoder.rb'
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in ruby-short_url.gemspec
|
4
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'bundler'
|
9
|
+
gem 'codeclimate-test-reporter', '~> 1.0'
|
10
|
+
gem 'minitest'
|
11
|
+
gem 'minitest-reporters'
|
12
|
+
gem 'rake'
|
13
|
+
gem 'rubocop'
|
14
|
+
gem 'simplecov'
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# Ruby::ShortUrl
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/toshimaru/ruby-short_url.svg?branch=master)](https://travis-ci.org/toshimaru/ruby-short_url)
|
4
|
+
![RuboCop](https://github.com/toshimaru/ruby-short_url/workflows/RuboCop/badge.svg)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/ruby-short_url.svg)](http://badge.fury.io/rb/ruby-short_url)
|
5
6
|
[![Test Coverage](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/coverage.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url/coverage)
|
6
7
|
[![Code Climate](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url)
|
7
|
-
[![Dependency Status](https://gemnasium.com/toshimaru/ruby-short_url.svg)](https://gemnasium.com/toshimaru/ruby-short_url)
|
8
8
|
|
9
|
-
|
9
|
+
## Description
|
10
|
+
|
11
|
+
Ruby implementation for generating Tiny URL. The implementation is based on [python-short_url](https://github.com/Alir3z4/python-short_url).
|
10
12
|
|
11
13
|
> A bit-shuffling approach is used to avoid generating consecutive, predictable URLs. However, the algorithm is deterministic and will guarantee that no collisions will occur.
|
12
14
|
|
@@ -47,7 +49,9 @@ class CustomEncoder < Ruby::ShortUrl::Encoder
|
|
47
49
|
super(alphabet: "0123abc", block_size: 5)
|
48
50
|
end
|
49
51
|
end
|
52
|
+
```
|
50
53
|
|
54
|
+
```rb
|
51
55
|
# > custom_encoder = CustomEncoder.new
|
52
56
|
# => #<CustomEncoder:0x007faf3babc830 @alphabet="0123abc", @block_size=5, @mask=31, @mapping=[0, 1, 2, 3, 4]>
|
53
57
|
#
|
@@ -68,14 +72,14 @@ end
|
|
68
72
|
|
69
73
|
## Development
|
70
74
|
|
71
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
76
|
|
73
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
74
78
|
|
75
79
|
## Contributing
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/toshimaru/ruby-short_url. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
|
4
|
-
task :
|
6
|
+
task default: :test
|
5
7
|
|
6
8
|
Rake::TestTask.new do |t|
|
7
|
-
t.libs <<
|
8
|
-
t.test_files = FileList[
|
9
|
+
t.libs << 'test'
|
10
|
+
t.test_files = FileList['test/**/test_*.rb']
|
9
11
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ruby-short_url'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "ruby-short_url"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ruby
|
2
4
|
module ShortUrl
|
3
5
|
# Original imprementation is here: https://github.com/Alir3z4/python-short_url
|
@@ -7,8 +9,8 @@ module Ruby
|
|
7
9
|
MIN_LENGTH = 5
|
8
10
|
|
9
11
|
def initialize(alphabet: DEFAULT_ALPHABET, block_size: DEFAULT_BLOCK_SIZE)
|
10
|
-
raise ArgumentError
|
11
|
-
raise ArgumentError
|
12
|
+
raise ArgumentError, 'alphabet must contain at least 2 characters.' if alphabet.length < 2
|
13
|
+
raise ArgumentError, 'block_size must be greater than 0.' unless block_size > 0
|
12
14
|
|
13
15
|
@alphabet = alphabet
|
14
16
|
@block_size = block_size
|
@@ -63,12 +65,14 @@ module Ruby
|
|
63
65
|
|
64
66
|
def _calc_result(result, n, x, y)
|
65
67
|
return result |= (1 << x) if n & (1 << y) != 0
|
68
|
+
|
66
69
|
result
|
67
70
|
end
|
68
71
|
|
69
72
|
def _enbase(x)
|
70
73
|
n = @alphabet.length
|
71
74
|
return @alphabet[x] if x < n
|
75
|
+
|
72
76
|
_enbase(x / n) + @alphabet[x % n]
|
73
77
|
end
|
74
78
|
end
|
data/lib/ruby-short_url.rb
CHANGED
data/ruby-short_url.gemspec
CHANGED
@@ -1,27 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'ruby/short_url/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'ruby-short_url'
|
7
9
|
spec.version = Ruby::ShortUrl::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
+
spec.authors = ['toshimaru']
|
11
|
+
spec.email = ['me@toshimaru.net']
|
10
12
|
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage =
|
13
|
+
spec.summary = 'Small library for generating tiny URL. Ruby port of python-short_url.'
|
14
|
+
spec.homepage = 'https://github.com/toshimaru/ruby-short_url'
|
13
15
|
|
14
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
16
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
-
spec.require_paths = [
|
18
|
-
|
19
|
-
spec.required_ruby_version = ">= 2.0.0"
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
|
23
|
-
spec.add_development_dependency "minitest"
|
24
|
-
spec.add_development_dependency "minitest-reporters"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "simplecov"
|
21
|
+
spec.required_ruby_version = '>= 2.3.0'
|
27
22
|
end
|
metadata
CHANGED
@@ -1,99 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-short_url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshimaru
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: codeclimate-test-reporter
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
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: minitest-reporters
|
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: rake
|
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: simplecov
|
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'
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
97
13
|
description:
|
98
14
|
email:
|
99
15
|
- me@toshimaru.net
|
@@ -101,7 +17,10 @@ executables: []
|
|
101
17
|
extensions: []
|
102
18
|
extra_rdoc_files: []
|
103
19
|
files:
|
20
|
+
- ".github/workflows/rubocop.yml"
|
104
21
|
- ".gitignore"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".rubocop_todo.yml"
|
105
24
|
- ".travis.yml"
|
106
25
|
- Gemfile
|
107
26
|
- LICENSE
|
@@ -124,15 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
43
|
requirements:
|
125
44
|
- - ">="
|
126
45
|
- !ruby/object:Gem::Version
|
127
|
-
version: 2.
|
46
|
+
version: 2.3.0
|
128
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
48
|
requirements:
|
130
49
|
- - ">="
|
131
50
|
- !ruby/object:Gem::Version
|
132
51
|
version: '0'
|
133
52
|
requirements: []
|
134
|
-
|
135
|
-
rubygems_version: 2.6.11
|
53
|
+
rubygems_version: 3.1.2
|
136
54
|
signing_key:
|
137
55
|
specification_version: 4
|
138
56
|
summary: Small library for generating tiny URL. Ruby port of python-short_url.
|