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 +4 -4
- data/README.md +8 -1
- data/lib/acts_as_identifier.rb +8 -0
- data/lib/acts_as_identifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7efb2fc3ad0b08e22b058358c990f15bf0a516c34c95824a8b197f1a4518e74b
|
4
|
+
data.tar.gz: 45eba2d5385ea34bdd6fa355001644ead93d65071f1bdc2499d980985c891b69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/acts_as_identifier.rb
CHANGED
@@ -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
|
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.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-
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xencoder
|