acts_as_identifier 1.1.3 → 1.3.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: 5949d5438578e6ba0dc781e97099ff60de4929de294a46dcb64a1b8f558fd805
4
- data.tar.gz: e3975e906f51cc8ff890ea819658d70cf6b97b35c0748639c61acd440fbd3d97
3
+ metadata.gz: f7d37c44af7c9196ea7fa5f5ec7b68dc3dcc95347ba4826eb4fab7bf466d3f98
4
+ data.tar.gz: b34c12b45f466b3f6bd3128374efb4c468a407f0df785b2008220a9bd8eb45cd
5
5
  SHA512:
6
- metadata.gz: 1652f9572cf96245f35ad3f36bda3f71ad8e1f271d316b213734c466e7898b772a09a5dd673c24f2a570a2d6342ca48a26766f337235ad19b39922fdb054d1bd
7
- data.tar.gz: 7d12df48ab6b85d74b1fa345491fcd1b319bb8f7623701bfcdf5f0fa17abf300880d37c5a4576d9ef8605e793993f6cfb4b79824f3817a2223209d822e8015f0
6
+ metadata.gz: 13462dd9829c0f19c3baac3adb30e029f3ee821bcab99058579fd730eceaadc7c2b9cce57c198c905544ac5d0388c2258b619c13cb885918398f0e842e726d41
7
+ data.tar.gz: b0b55716bc29d0bf8963b8cf78f420ba2518e7dd4a019249f8155dc8f32ab39a44a106e1451f80881642f858f7e4eede5a9f6ba9df64fc6fa7efd35077fabd4a
data/README.md CHANGED
@@ -31,9 +31,16 @@ Account.create
31
31
  # => #<Account:0x00007fcdb90830c0 id: 1, name: nil, tenant_id: nil, slug: "s-EPaPaP">
32
32
  Account.create
33
33
  # => #<Account:0x00007fcdb90830c0 id: 2, name: nil, tenant_id: nil, slug: "s-HSo0u4">
34
-
35
34
  ```
36
35
 
36
+ ## Features
37
+
38
+ - *`ActiveRecord`*.find_by_decoded_*`identifier`*('s-EPaPaP') => Actually find by id, id is decoded from identifier, with this method you don't need to add extra index for *`identifier`*
39
+ - *`ActiveRecord`*.find_by_decoded_*`identifier`*!('s-EPaPaP') => equal to find_by_xx!
40
+ - *`ActiveRecord`*.*decode_`identifier`*('s-EPaPaP') => decode identifier to id
41
+ - *`ActiveRecord`*.*encode_`identifier`*(1) => encode id to identifier
42
+ - *`ActiveRecord`*.*`identifier`*_encoder => encoder instance, see [xencoder](https://github.com/xiaohui-zhangxh/xencoder)
43
+
37
44
  ## Installation
38
45
 
39
46
  ```ruby
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsIdentifier
4
- VERSION = '1.1.3'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -44,11 +44,19 @@ module ActsAsIdentifier
44
44
  "#{prefix}#{send("#{attr}_encoder").encode(num)}"
45
45
  end
46
46
 
47
+ define_singleton_method "find_by_decoded_#{attr}" do |str|
48
+ find_by(id_column => public_send("decode_#{attr}", str))
49
+ end
50
+
51
+ define_singleton_method "find_by_decoded_#{attr}!" do |str|
52
+ find_by!(id_column => public_send("decode_#{attr}", str))
53
+ end
54
+
47
55
  define_method "acts_as_identifier__update_#{attr}" do
48
56
  update_column attr, self.class.send("encode_#{attr}", send(id_column))
49
57
  end
50
58
 
51
- before_commit :"acts_as_identifier__update_#{attr}", if: -> { previous_changes.key?(id_column.to_s) && !destroyed? }
59
+ after_save :"acts_as_identifier__update_#{attr}", if: -> { previous_changes.key?(id_column.to_s) && !destroyed? }
52
60
  end
53
61
  end
54
62
  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.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xencoder
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.1
33
+ version: 7.0.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.1
40
+ version: 7.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ 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.9
85
+ rubygems_version: 3.3.7
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Auto-generate unique identifier value for Active Record