exid 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +7 -7
- data/lib/exid/record.rb +8 -8
- data/lib/exid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 064c2fa33e682ce0cc265bfc7504b5880468084b27d0a494b00de81fd49d24d2
|
4
|
+
data.tar.gz: 4f1d3c6f0a3dec4cdfab9a944b8914893cecb4440f4c6402d10adc56066a4c94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93cf7e89ba36affd92b44427d3c502a24ec746551a393e4ec20854810db697cbf5856a6aa7c372df9dee6bc4fda6650eb22f1e70849b2dd450b788483860b6b1
|
7
|
+
data.tar.gz: d70ea9392154d335c8e1cb241e07ea1d71162141264fcd5e99c0063a7a404fb70a849d512c0576d965325f9aff58732b01ac6f20ca2de626bdf25a9fa16be0c5
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ class User < ApplicationRecord
|
|
31
31
|
# Optional, but recommended. Use the Exid value as the primary object
|
32
32
|
# identier.
|
33
33
|
|
34
|
-
def to_param =
|
34
|
+
def to_param = exid_value
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
@@ -44,14 +44,14 @@ user = User.create!(uuid: "018977bb-02f0-729c-8c00-2f384eccb763")
|
|
44
44
|
Following methods are now available on the instance class.
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
user.
|
47
|
+
user.exid_value # => "user_02TOxMzOS0VaLzYiS3NPd9"
|
48
48
|
|
49
|
-
user.
|
49
|
+
user.exid_prefix_name # => "user"
|
50
50
|
|
51
|
-
user.
|
51
|
+
user.exid_field # => :uuid
|
52
52
|
```
|
53
53
|
|
54
|
-
The `
|
54
|
+
The `exid_handle` instanec method simply returns last 10 characters of
|
55
55
|
identifier. This might be useful for displaying in the UI as distinguishing
|
56
56
|
identifier. If the UUID7 is used as the identifier, the first few characters
|
57
57
|
are not random. They come from the timestamp, so they will be the same for most
|
@@ -59,9 +59,9 @@ objects created at the same time. Pass integer as the argument to get the last
|
|
59
59
|
N characters.
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
user.
|
62
|
+
user.exid_handle # => "OBtqZqRhLm"
|
63
63
|
|
64
|
-
user.
|
64
|
+
user.exid_handle(6) # => "ZqRhLm"
|
65
65
|
```
|
66
66
|
|
67
67
|
The `Exid::Record` also offers couple of instance methods designed load
|
data/lib/exid/record.rb
CHANGED
@@ -20,8 +20,8 @@ module Exid
|
|
20
20
|
|
21
21
|
self.class.register_module(
|
22
22
|
Entry.new(
|
23
|
-
prefix: base.
|
24
|
-
field: base.
|
23
|
+
prefix: base.exid_prefix_name,
|
24
|
+
field: base.exid_field,
|
25
25
|
klass: base,
|
26
26
|
),
|
27
27
|
)
|
@@ -80,7 +80,7 @@ module Exid
|
|
80
80
|
|
81
81
|
def build_module_value(prefix, field)
|
82
82
|
Module.new do
|
83
|
-
define_method :
|
83
|
+
define_method :exid_value do
|
84
84
|
Coder.encode(prefix, send(field))
|
85
85
|
end
|
86
86
|
|
@@ -89,19 +89,19 @@ module Exid
|
|
89
89
|
# last bytes of encoded of UUID7 is more likely to be unique. This for
|
90
90
|
# display only, do not use this to fetch records, etc.
|
91
91
|
|
92
|
-
define_method :
|
93
|
-
|
92
|
+
define_method :exid_handle do |amount = 10|
|
93
|
+
exid_value.split("_").last[-amount..-1]
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
def build_module_shared(prefix, field)
|
99
99
|
Module.new do
|
100
|
-
define_method :
|
100
|
+
define_method :exid_prefix_name do
|
101
101
|
prefix
|
102
102
|
end
|
103
103
|
|
104
|
-
define_method :
|
104
|
+
define_method :exid_field do
|
105
105
|
field
|
106
106
|
end
|
107
107
|
end
|
@@ -109,7 +109,7 @@ module Exid
|
|
109
109
|
|
110
110
|
def build_module_static(prefix, field)
|
111
111
|
Module.new do
|
112
|
-
define_method :
|
112
|
+
define_method :exid_loader do |eid|
|
113
113
|
Coder.decode(eid) => ^prefix, value
|
114
114
|
find_sole_by(field => value)
|
115
115
|
end
|
data/lib/exid/version.rb
CHANGED