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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78ce10327504b42999d641f7f5e1c1783cf20208
4
- data.tar.gz: 72dde477590fe6e4618cfa38d21a17a7923ca5ad
3
+ metadata.gz: 7838e770d8464e2dee709af97762ffe81aa169a6
4
+ data.tar.gz: 9d6d15ad2f68c4a00d000f752ad47d45fa5ec4df
5
5
  SHA512:
6
- metadata.gz: fb41de55bd4c95a0ec76ad8f851f85aaaff6a710a822c46e50f8453e5f70927fa7c8aaf221cc41d7c493907542fd48e8359bb0ceec47a1e5e026b9c2d53ead3f
7
- data.tar.gz: 5cc3fe49ce4849d4e720f83c9d09ef0ad984610187a1ab1db549d55351c247d79e3e3c238e1a537187842b46e39b793b03c1b4eaad1efa84cfd9197a98c03b19
6
+ metadata.gz: 87ddcc37962df16da3cd708207ed69b2ff7f08d97fea78b7ad9a3b936f94ecfbb7486efbfcea8cf4fbcb9392256c151cdeef745ffe6ce2553dfb325eb4544d46
7
+ data.tar.gz: 8556ae0a406ac8179e401d0023ded1a78577ce8d27ef4e1ae05c899d1b067009edce64fa5eba4731585f63422235ee88f5f68a9c646d582940fdf1d37049f6d5
@@ -1,8 +1,14 @@
1
1
  language: ruby
2
+
2
3
  bundler_args: --without documentation
4
+
3
5
  rvm:
4
- - 2.1.2
6
+ - 2.4.0
7
+ - 2.3.3
8
+ - 2.2.6
9
+ - 2.1.10
5
10
  - 2.0.0
6
- - 1.9.3
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-19mode
11
+ - jruby-9.1.6.0
12
+ - jruby-1.7.26
13
+
14
+ sudo: false
data/Gemfile CHANGED
@@ -6,3 +6,7 @@ gemspec
6
6
  group :development do
7
7
  gem "rake"
8
8
  end
9
+
10
+ group :test do
11
+ gem "minitest"
12
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014 Peter Hellberg
1
+ Copyright (c) 2013-2016 Peter Hellberg
2
2
 
3
3
  MIT License
4
4
 
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://secure.travis-ci.org/peterhellberg/hashids.rb.png)](http://travis-ci.org/peterhellberg/hashids.rb)
9
- (2.1.2, 2.0.0, 1.9.3, jruby-19mode, rbx-19mode)
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
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Hashids
4
- VERSION = "1.0.2"
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
- if numbers.empty? || numbers.reject { |n| Integer(n) && n >= 0 }.any?
30
- ""
31
- else
32
- internal_encode(numbers)
33
- end
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.gsub(/[#{@guards}]/, " ")
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].gsub(/[#{@seps}]/, " ")
124
+ breakdown = breakdown[1 .. -1].tr(@seps, " ")
125
125
  array = breakdown.split(" ")
126
126
 
127
- array.length.times do |i|
128
- sub_hash = array[i]
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?(Fixnum)
263
- raise MinLengthError, "The min length must be a Fixnum"
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
@@ -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 a Fixnum" do
245
- -> { Hashids.new('salt', :not_a_fixnum)}.
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.2
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: 2014-12-13 00:00:00.000000000 Z
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.4.3
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.