acts_as_identifier 1.1.3 → 1.1.4

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: 7efb2fc3ad0b08e22b058358c990f15bf0a516c34c95824a8b197f1a4518e74b
4
+ data.tar.gz: 45eba2d5385ea34bdd6fa355001644ead93d65071f1bdc2499d980985c891b69
5
5
  SHA512:
6
- metadata.gz: 1652f9572cf96245f35ad3f36bda3f71ad8e1f271d316b213734c466e7898b772a09a5dd673c24f2a570a2d6342ca48a26766f337235ad19b39922fdb054d1bd
7
- data.tar.gz: 7d12df48ab6b85d74b1fa345491fcd1b319bb8f7623701bfcdf5f0fa17abf300880d37c5a4576d9ef8605e793993f6cfb4b79824f3817a2223209d822e8015f0
6
+ metadata.gz: f2b83dc95625f42cab1b5b3e10e125e22c70f5fcbd06c4dc94a63f99916d5a4a0da14390bcb93314d96a8b01995a351b67141fc56692e8fabe718f447a732d00
7
+ data.tar.gz: 5dd8b25d169fe579cc3a6e48d34fa82483e37e882a57b5a1069543beaceb91103a47605b8a8cd86db98d3b7a10fb88d10a29522a54fac8b9a689bd9123180a7e
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
@@ -44,6 +44,14 @@ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsIdentifier
4
- VERSION = '1.1.3'
4
+ VERSION = '1.1.4'
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.3
4
+ version: 1.1.4
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: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xencoder