hashids 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -4
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +10 -2
- data/lib/hashids.rb +12 -12
- data/spec/hashids_spec.rb +11 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7838e770d8464e2dee709af97762ffe81aa169a6
|
4
|
+
data.tar.gz: 9d6d15ad2f68c4a00d000f752ad47d45fa5ec4df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ddcc37962df16da3cd708207ed69b2ff7f08d97fea78b7ad9a3b936f94ecfbb7486efbfcea8cf4fbcb9392256c151cdeef745ffe6ce2553dfb325eb4544d46
|
7
|
+
data.tar.gz: 8556ae0a406ac8179e401d0023ded1a78577ce8d27ef4e1ae05c899d1b067009edce64fa5eba4731585f63422235ee88f5f68a9c646d582940fdf1d37049f6d5
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -5,8 +5,8 @@ Use hashids when you do not want to expose your database ids to the user.
|
|
5
5
|
|
6
6
|
[http://hashids.org/ruby/](http://hashids.org/ruby/)
|
7
7
|
|
8
|
-
[![Build Status](https://
|
9
|
-
(2.
|
8
|
+
[![Build Status](https://travis-ci.org/peterhellberg/hashids.rb.svg?branch=master)](http://travis-ci.org/peterhellberg/hashids.rb)
|
9
|
+
(2.4.0 2.3.1, 2.2.5, 2.1.9, 2.0.0, jruby-9.0.5.0, jruby-1.7.20)
|
10
10
|
|
11
11
|
## What is it?
|
12
12
|
|
@@ -208,6 +208,14 @@ hex_str = hashids.decode_hex("kRNrpKlJ")
|
|
208
208
|
|
209
209
|
## Changelog
|
210
210
|
|
211
|
+
**1.0.3**
|
212
|
+
|
213
|
+
- Support for Ruby 2.4.0
|
214
|
+
|
215
|
+
**1.0.2**
|
216
|
+
|
217
|
+
- Handle invalid input by raising InputError
|
218
|
+
|
211
219
|
**1.0.1**
|
212
220
|
|
213
221
|
- Final alphabet length can now be shorter than the minimum alphabet length
|
data/lib/hashids.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class Hashids
|
4
|
-
VERSION = "1.0.
|
4
|
+
VERSION = "1.0.3"
|
5
5
|
|
6
6
|
MIN_ALPHABET_LENGTH = 16
|
7
7
|
SEP_DIV = 3.5
|
@@ -26,11 +26,11 @@ class Hashids
|
|
26
26
|
def encode(*numbers)
|
27
27
|
numbers.flatten! if numbers.length == 1
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
numbers.map! { |n| Integer(n) } # raises if conversion fails
|
30
|
+
|
31
|
+
return '' if numbers.empty? || numbers.any? { |n| n < 0 }
|
32
|
+
|
33
|
+
internal_encode(numbers)
|
34
34
|
end
|
35
35
|
|
36
36
|
def encode_hex(str)
|
@@ -114,18 +114,18 @@ class Hashids
|
|
114
114
|
def internal_decode(hash, alphabet)
|
115
115
|
ret = []
|
116
116
|
|
117
|
-
breakdown = hash.
|
117
|
+
breakdown = hash.tr(@guards, " ")
|
118
118
|
array = breakdown.split(" ")
|
119
119
|
|
120
120
|
i = [3,2].include?(array.length) ? 1 : 0
|
121
121
|
|
122
122
|
if breakdown = array[i]
|
123
123
|
lottery = breakdown[0]
|
124
|
-
breakdown = breakdown[1 .. -1].
|
124
|
+
breakdown = breakdown[1 .. -1].tr(@seps, " ")
|
125
125
|
array = breakdown.split(" ")
|
126
126
|
|
127
|
-
array.length.times do |
|
128
|
-
sub_hash = array[
|
127
|
+
array.length.times do |time|
|
128
|
+
sub_hash = array[time]
|
129
129
|
buffer = lottery + salt + alphabet
|
130
130
|
alphabet = consistent_shuffle(alphabet, buffer[0, alphabet.length])
|
131
131
|
|
@@ -259,8 +259,8 @@ class Hashids
|
|
259
259
|
raise SaltError, "The salt must be a String"
|
260
260
|
end
|
261
261
|
|
262
|
-
unless min_hash_length.kind_of?(
|
263
|
-
raise MinLengthError, "The min length must be a
|
262
|
+
unless min_hash_length.kind_of?(Integer)
|
263
|
+
raise MinLengthError, "The min length must be a Integer"
|
264
264
|
end
|
265
265
|
|
266
266
|
unless min_hash_length >= 0
|
data/spec/hashids_spec.rb
CHANGED
@@ -115,6 +115,15 @@ describe Hashids do
|
|
115
115
|
hashids.encode([1,2,3]).must_equal "laHquq"
|
116
116
|
end
|
117
117
|
|
118
|
+
it "can encode string encoded number" do
|
119
|
+
hashids.encode('1').must_equal "NV"
|
120
|
+
hashids.encode('-1').must_equal ""
|
121
|
+
end
|
122
|
+
|
123
|
+
it "raises exception if integer conversion fails" do
|
124
|
+
-> { hashids.encode('-') }.must_raise ArgumentError
|
125
|
+
end
|
126
|
+
|
118
127
|
it "returns an empty string if no numbers" do
|
119
128
|
hashids.encode.must_equal ""
|
120
129
|
end
|
@@ -241,8 +250,8 @@ describe Hashids do
|
|
241
250
|
must_raise Hashids::SaltError
|
242
251
|
end
|
243
252
|
|
244
|
-
it "raises an ArgumentError unless the min_length is
|
245
|
-
-> { Hashids.new('salt', :
|
253
|
+
it "raises an ArgumentError unless the min_length is an Integer" do
|
254
|
+
-> { Hashids.new('salt', :not_an_integer)}.
|
246
255
|
must_raise Hashids::MinLengthError
|
247
256
|
end
|
248
257
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Hellberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use hashids when you do not want to expose your database ids to the user.
|
14
14
|
email:
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.6.8
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: Generate YouTube-like hashes from one or many numbers.
|