acts_as_identifier 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/acts_as_identifier.rb +9 -5
- data/lib/acts_as_identifier/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 445be323d571181bfd5130ec7b4551f459a2d42ae59f382f3548e06d9fbb996c
|
4
|
+
data.tar.gz: a53b03f119d4fe291a8bae5129dbcf685cc19828b34967e9c366d870d8992ffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72fab7b0cc1aff1c5556f1de26b4e3067d8a39cca603a4fdbb2150f8995f1b4ce89100b284fa60db3b21fa3925dea99c9e4378ede5c266dd81e3628285b7aa5b
|
7
|
+
data.tar.gz: ff02f71aa8728bbf76972d2c84a76e064b2b44930ba2734f62efb3ed841bc09c29b1b4406cbad93daaa6057d4344761f3b8881a8d5da992857393597cd06484b
|
data/README.md
CHANGED
@@ -14,12 +14,12 @@ class Account < ActiveRecord::Base
|
|
14
14
|
#
|
15
15
|
# == default options
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
17
|
+
# attr: :identifier,
|
18
|
+
# seed: 1,
|
19
|
+
# length: 6,
|
20
|
+
# prefix: nil,
|
21
|
+
# id_column: :id,
|
22
|
+
# chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
23
23
|
#
|
24
24
|
acts_as_identifier
|
25
25
|
# or customize options:
|
data/lib/acts_as_identifier.rb
CHANGED
@@ -14,15 +14,15 @@ module ActsAsIdentifier
|
|
14
14
|
# == Automatically generate unique string based on id
|
15
15
|
#
|
16
16
|
# @param attr [String, Symbol] column name, default: :identifier
|
17
|
+
# @param seed [Integer] Random seed, default: 1
|
17
18
|
# @param length [Integer] length of identifier, default: 6
|
18
|
-
# @params prefix [String, Symbol] add prefix to value, default:
|
19
|
+
# @params prefix [String, Symbol] add prefix to value, default: nil
|
19
20
|
# @params id_column [String, Symbol] column name of id, default: :id
|
20
|
-
# @params chars [
|
21
|
-
# @params mappings [Array<String>] mappings must have the same characters as chars
|
21
|
+
# @params chars [String] chars for generating identifier
|
22
22
|
def acts_as_identifier(attr = :identifier,
|
23
23
|
seed: 1,
|
24
24
|
length: 6,
|
25
|
-
prefix:
|
25
|
+
prefix: nil,
|
26
26
|
id_column: :id,
|
27
27
|
chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
28
28
|
define_singleton_method "#{attr}_encoder" do
|
@@ -33,7 +33,11 @@ module ActsAsIdentifier
|
|
33
33
|
end
|
34
34
|
|
35
35
|
define_singleton_method "decode_#{attr}" do |str|
|
36
|
-
|
36
|
+
if prefix
|
37
|
+
return nil unless str.to_s.start_with?(prefix)
|
38
|
+
str = str[prefix.length..-1]
|
39
|
+
end
|
40
|
+
str && send("#{attr}_encoder").decode(str)
|
37
41
|
end
|
38
42
|
|
39
43
|
define_singleton_method "encode_#{attr}" do |num|
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xencoder
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- xiaohui@tanmer.com
|
58
58
|
executables: []
|
@@ -67,7 +67,7 @@ homepage: https://github.com/xiaohui-zhangxh/acts_as_identifier
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
metadata: {}
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -82,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.0.
|
86
|
-
signing_key:
|
85
|
+
rubygems_version: 3.0.8
|
86
|
+
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Auto-generate unique identifier value for Active Record
|
89
89
|
test_files: []
|