cool_id 0.2.0 → 0.2.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/CHANGELOG.md +29 -1
- data/README.md +7 -2
- data/lib/cool_id/version.rb +1 -1
- data/lib/cool_id.rb +3 -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: e54329c6343b05066daa4f6f4cc7f43786d61206cf544f68adb711e11e17b90b
|
4
|
+
data.tar.gz: 357e081efb8d3cc4261dd4f388f85513cbf9ca6c7bf5c9bf8362b7e7efeee52c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffb6f03399abc0233718b40c56bb846639e3b680a7afeb431de3eab8d41e2e5c388352da1f964cd796278ba50ce904c7ff83aa5597a0d35d79698fe7ca7b911d
|
7
|
+
data.tar.gz: 946b40fa180dd8e75f08e683cd94618475be7cb65d9198e37a8c9c91d3c02286fb1aacec98e43534bfd02bae745ed186bf2c9ee5e902f366b098f6f7510b510d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
1
3
|
## [Unreleased]
|
2
4
|
|
3
|
-
## [0.
|
5
|
+
## [0.2.2] - 2025-05-29
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- support including separators in the prefix
|
10
|
+
|
11
|
+
## [0.2.1] - 2025-01-09
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- Generate up-to-date Gemfile.lock
|
16
|
+
|
17
|
+
## [0.2.0] - 2025-01-09
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- Drop nanoid dependency, switch to SecureRandom from stdlib
|
22
|
+
|
23
|
+
## [0.1.9] - 2024-08-16
|
24
|
+
|
25
|
+
### Added
|
4
26
|
|
5
27
|
- Initial release
|
28
|
+
|
29
|
+
[Unreleased]: https://github.com/schpet/cool_id/compare/v0.2.2...HEAD
|
30
|
+
[0.2.2]: https://github.com/schpet/cool_id/compare/v0.2.1...v0.2.2
|
31
|
+
[0.2.1]: https://github.com/schpet/cool_id/compare/v0.2.0...v0.2.1
|
32
|
+
[0.2.0]: https://github.com/schpet/cool_id/compare/v0.1.9...v0.2.0
|
33
|
+
[0.1.9]: https://github.com/schpet/cool_id/releases/tag/v0.1.9
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# cool id
|
2
2
|
|
3
|
-
|
3
|
+
rails apps are given the option of integer ids, uuids or global ids. these are all annoying in their own ways:
|
4
|
+
|
5
|
+
- integer ids are guessable, expose how many records you have and are easy to get crossed between tables _“oh i meant profile 123 not user 123...”_
|
6
|
+
- uuids mostly solve that but are long and ugly in urls which is unforgivible
|
7
|
+
- global ids are even longer and uglier, they are often base64 encoded so it's annoying to drop into your database to lookup records
|
8
|
+
|
9
|
+
enter cool id: use a random string id, with a little prefix like stripe. e.g. `usr_vktd1b5v84lr` for a user, or `prd_vktd1b5v84lr` for a product. cool_id makes this easy to apply to all of your models and doesn't bring in any extra dependencies. your urls will be beautiful.
|
4
10
|
|
5
11
|
## usage
|
6
12
|
|
@@ -86,7 +92,6 @@ CoolId.locate("prd_vktd1b5v84lr") # => #<Product id: 1, public_id: "prd_vktd1b5
|
|
86
92
|
|
87
93
|
this approach allows you to avoid exposing your primary keys, read David Bryant Copeland's [Create public-facing unique keys alongside your primary keys](https://naildrivin5.com/blog/2024/08/26/create-public-facing-unique-keys-alongside-your-primary-keys.html) to learn why you might want to do this. it also allows you to adopt cool_id more easily in a project that already has some data.
|
88
94
|
|
89
|
-
|
90
95
|
## installation
|
91
96
|
|
92
97
|
add cool_id to your Gemfile:
|
data/lib/cool_id/version.rb
CHANGED
data/lib/cool_id.rb
CHANGED
@@ -133,7 +133,9 @@ module CoolId
|
|
133
133
|
# @param id [String] The CoolId to parse.
|
134
134
|
# @return [Id, nil] The parsed Id object, or nil if parsing fails.
|
135
135
|
def parse(id)
|
136
|
-
|
136
|
+
components = id.split(CoolId.separator)
|
137
|
+
prefix = components[0..-2].join(CoolId.separator)
|
138
|
+
key = components[-1]
|
137
139
|
model_class = @prefix_map[prefix]
|
138
140
|
return nil unless model_class
|
139
141
|
id_field = CoolId.resolve_cool_id_field(model_class)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cool_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Schilling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|