acts_as_identifier 1.1.2 → 1.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: 1d0ef5e8642b9ffa1aaf5dfa6e73a6d3b76885d08c90c8d6b74799c650b9ad86
4
- data.tar.gz: 6637b7954d14b63f122ba48ba168fcdd6c8963e85188336d113b3d9c94c34a54
3
+ metadata.gz: 0f85e5ea4c8ff461ea96969666a1db7dc34faa5ac4b3511e804657d2791401e8
4
+ data.tar.gz: e8473cad55d9d1afc38ffb5206a41be4eed61a9513cc676c0c153e9d42b82255
5
5
  SHA512:
6
- metadata.gz: 53908ce8a218741b7a2466f77e99b6fb80ef22460d4d920f43585038d92913a573dc9142c42d3e227e93c8771d869d0467b4a80cdb33ed207e9c0dee18e32a2b
7
- data.tar.gz: 21eb32be02eb86a40a84a00691800f48cb80831904afa6606ede41c1c985cb03cee67b134d083611b7b557ada0ea7697dcc3f5b0e1ab6674e15d08792b860197
6
+ metadata.gz: b816f50da7fd540b38f126475d24bff59cbfdf60b45fbf3a2da7688742182a563b9fa5902645ce7604e9343678a78e378c89a9ab926c09da4320b76a839cfaaf
7
+ data.tar.gz: b74edf03c4100bf85bc447691692dda80745d17af042ba4d800b719f2095d76b0b1f4e056a2e8d5ad292c2f4de6adf87d0c3f9d21430d9cf392a4db105982ffb
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.2'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -44,13 +44,19 @@ module ActsAsIdentifier
44
44
  "#{prefix}#{send("#{attr}_encoder").encode(num)}"
45
45
  end
46
46
 
47
- define_method "update_#{attr}_before_commit" do
48
- if previous_changes.key?(id_column.to_s) && !destroyed?
49
- update_column attr, self.class.send("encode_#{attr}", send(id_column))
50
- end
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
+
55
+ define_method "acts_as_identifier__update_#{attr}" do
56
+ update_column attr, self.class.send("encode_#{attr}", send(id_column))
51
57
  end
52
58
 
53
- before_commit :"update_#{attr}_before_commit"
59
+ before_commit :"acts_as_identifier__update_#{attr}", if: -> { previous_changes.key?(id_column.to_s) && !destroyed? }
54
60
  end
55
61
  end
56
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.2
4
+ version: 1.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: 2021-08-05 00:00:00.000000000 Z
11
+ date: 2022-05-27 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.3
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Auto-generate unique identifier value for Active Record