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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56a684b60d5b16c517e29049493feee1bed693c74b5de33fd18100454fa53547
4
- data.tar.gz: 81c9a2c9b6a3c7cc7fd87ef3123f595cab818783018e22b9423ed6aee085fd2c
3
+ metadata.gz: 50941b62619d0fa3829df18f02e97e46d02e7b35f052db3c64d9c7b821699826
4
+ data.tar.gz: 728fbeb1a33e0dd5f5f734f5a1e18821320df7118e79717b5bc543c9fceacec4
5
5
  SHA512:
6
- metadata.gz: 178d1de2dd01dce8afdeb933cc9bec7a18b38132e8ead74dc1271d5d33eb6e7ee37f72c4bf0c8142fc9d7e7b4c1f2bd5136cd2f9fbbd74ada4be9d7e854573af
7
- data.tar.gz: c8c1d26f4ec778832a14dd1bae837f6c90786098302dccf0ed3938e82930d54aab4f26d59cf17b1815a03242ebeba3f4c8174dc01913ddc2cd8f4d3c8263a8d8
6
+ metadata.gz: d323726b48026b4bb396a8837d47f1c45b6f3fded3972c3c7a51e7ca3bccbfdcfa11f33ba895dd081b21a2c3b79327f9348ad6987a0bff2695c32b868c6c1fd2
7
+ data.tar.gz: 6fba6c6ade83590f4c91909298da3133d01665014c187d12324d129f8d03a992cfaab01cab7693d869c124ec233e8e485de17ca7a3175e15b2c7aed6be9abbfe
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActsAsIdentifier
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/acts_as_identifier.svg)](https://badge.fury.io/rb/acts_as_identifier)
4
+
3
5
  Automatically generate unique secure random string for one or more columns of ActiveRecord.
4
6
 
5
7
  ## Usage
@@ -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
- def acts_as_identifier(attr = nil, length: 6, case_sensitive: true, max_loop: 100, scope: [])
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsIdentifier
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  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.1.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-07 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails