acts_as_identifier 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e24cb96573ceb1e6439218ab0791c25fca1ff4de0e5320019039a2f1e56e0ce
4
- data.tar.gz: 1958d5829d519f497c3c215183f7d071d7e68ccfb66521d2a14db3da0a26e3ba
3
+ metadata.gz: 445be323d571181bfd5130ec7b4551f459a2d42ae59f382f3548e06d9fbb996c
4
+ data.tar.gz: a53b03f119d4fe291a8bae5129dbcf685cc19828b34967e9c366d870d8992ffa
5
5
  SHA512:
6
- metadata.gz: ed7ff77501adb90ca3b030cda300d974cc92c577863589316a3e4a34f0d14dbf84c2f57e167af13f816ef0ddb9f946b754e3a6d5e3e454f4f42e3ad85180b8d7
7
- data.tar.gz: fab6c448257751fd41b08af088f59753d3154ef64bd506604e23881122221bb9338a824bfc0b4f19b697fb2e0762b03d313187dbf56e1d6141db080b87eaf2d7
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
- # def acts_as_identifier(attr = :identifier,
18
- # seed: 1,
19
- # length: 6,
20
- # prefix: '',
21
- # id_column: :id,
22
- # chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
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:
@@ -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 [Array<String>] 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
- send("#{attr}_encoder").decode(str[prefix.length..-1])
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsIdentifier
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
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: 1.1.0
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-01-27 00:00:00.000000000 Z
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.6
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: []