acts_as_identifier 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/acts_as_identifier.rb +3 -2
- data/lib/acts_as_identifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50941b62619d0fa3829df18f02e97e46d02e7b35f052db3c64d9c7b821699826
|
4
|
+
data.tar.gz: 728fbeb1a33e0dd5f5f734f5a1e18821320df7118e79717b5bc543c9fceacec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d323726b48026b4bb396a8837d47f1c45b6f3fded3972c3c7a51e7ca3bccbfdcfa11f33ba895dd081b21a2c3b79327f9348ad6987a0bff2695c32b868c6c1fd2
|
7
|
+
data.tar.gz: 6fba6c6ade83590f4c91909298da3133d01665014c187d12324d129f8d03a992cfaab01cab7693d869c124ec233e8e485de17ca7a3175e15b2c7aed6be9abbfe
|
data/README.md
CHANGED
data/lib/acts_as_identifier.rb
CHANGED
@@ -19,7 +19,8 @@ module ActsAsIdentifier
|
|
19
19
|
# @param case_sensitive [Boolean] Case-sensitive? default: true
|
20
20
|
# @param max_loop [Integer] max loop count to generate unique identifier, in case of running endless loop, default: 100
|
21
21
|
# @param scope [Array<Symbol,String>] scope of identifier, default: []
|
22
|
-
|
22
|
+
# @params prefix [String, Symbol] add prefix to value, default: ''
|
23
|
+
def acts_as_identifier(attr = nil, length: 6, case_sensitive: true, max_loop: 100, scope: [], prefix: '')
|
23
24
|
attr ||= :identifier
|
24
25
|
scope = Array(scope)
|
25
26
|
method = case_sensitive ? :alphanumeric : :hex
|
@@ -30,7 +31,7 @@ module ActsAsIdentifier
|
|
30
31
|
n = 0
|
31
32
|
loop do
|
32
33
|
n += 1
|
33
|
-
value = send("#{attr}=", SecureRandom.send(method, length))
|
34
|
+
value = send("#{attr}=", "#{prefix}#{SecureRandom.send(method, length)}")
|
34
35
|
break unless query.where(attr => value).exists?
|
35
36
|
raise LoopTooManyTimesError if n > max_loop
|
36
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_identifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|