nanoid 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/nanoid.rb +12 -15
  3. data/lib/nanoid/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73d89528124fe3ce6e356621bdd47dafb3c0d63e
4
- data.tar.gz: 92595e297bdad2d9608b03c67434e75848ac2ee1
2
+ SHA256:
3
+ metadata.gz: 8be37a0041248f42abd8449d04aea6562c82d6f5024ecd96f2822a234f174e5e
4
+ data.tar.gz: f25ad50c1113a25faeebd80f1e1e982c5d269ee600d6c39434247951535e1028
5
5
  SHA512:
6
- metadata.gz: 28c149c686bea5f5c7ec5a9c59d819f014c2ac17b9a7be70200eb21d8cb1e203395dab02de49b67dc956ffd51cb57bee23f6ec86a52bdeb7d18c252a51ffcec0
7
- data.tar.gz: cda8cfada149a6065ae8cd9f10a67858cc22af1e80e14d445b1701c34e643bd7de7373cdc3048568d534e8b80d6c26f1c5e4bcdd7f262ae6a4d8f0a0b2eaf8d1
6
+ metadata.gz: 39b1f9dc17118b306e6da1278756a4a786cc4fd5b7c7146dd971c80acb65787717158f6e1ed6cea44fc29b9bbf56fe30e036042b84acdd2efdbf0858d44a2467
7
+ data.tar.gz: be9753553725d9935464b09b85a60e6be23b54543bac1f8067758b156f4cbafb23b5fbfe98eb864d522f8b5dd360887a620a2dd05fd8e8a9ce3725d3f9734b69
@@ -14,8 +14,8 @@ module Nanoid
14
14
  def self.simple_generate(size:)
15
15
  bytes = random_bytes(size)
16
16
 
17
- (0...size).reduce('') do |acc, i|
18
- acc + SAFE_ALPHABET[bytes[i] & 63]
17
+ (0...size).reduce(''.dup) do |acc, i|
18
+ acc << SAFE_ALPHABET[bytes[i] & 63]
19
19
  end
20
20
  end
21
21
 
@@ -24,22 +24,19 @@ module Nanoid
24
24
  mask = (2 << Math.log(alphabet_size - 1) / Math.log(2)) - 1
25
25
  step = (1.6 * mask * size / alphabet_size).ceil
26
26
 
27
- id = ''
28
- catch :computed do
29
- loop do
30
- bytes = random_bytes(size)
31
- (0...step).each do |i|
32
- byte = bytes[i] & mask
33
- character = byte && alphabet[byte]
34
- if character
35
- id = "#{id}#{character}"
36
- throw :computed if id.size == size
37
- end
27
+ id = ''.dup
28
+
29
+ loop do
30
+ bytes = random_bytes(size)
31
+ (0...step).each do |idx|
32
+ byte = bytes[idx] & mask
33
+ character = byte && alphabet[byte]
34
+ if character
35
+ id << character
36
+ return id if id.size == size
38
37
  end
39
38
  end
40
39
  end
41
-
42
- id
43
40
  end
44
41
 
45
42
  def self.random_bytes(size)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NanoId
4
- VERSION = '0.2.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radovan Smitala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.6.13
111
+ rubygems_version: 2.7.7
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Ruby implementation of Nanoid, secure URL-friendly unique ID generator