cool_id 0.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f17a2d8e6446ee2a6d8250d1a78cc3b826cadea81c27ff9c552edc66d72639f
4
- data.tar.gz: b7f1d8476cdb4d000cf3a6da8153fe617a6f6dce84b2f772b8e7633f55d501f1
3
+ metadata.gz: e54329c6343b05066daa4f6f4cc7f43786d61206cf544f68adb711e11e17b90b
4
+ data.tar.gz: 357e081efb8d3cc4261dd4f388f85513cbf9ca6c7bf5c9bf8362b7e7efeee52c
5
5
  SHA512:
6
- metadata.gz: bba3537a910dc58bc8a3db17b1ec29fa3bc50ef20337f2242148fe334cb911f2e5d1d9149dde8c0e617692a483d0919e3cc98e16557014261b90af8daf5ac647
7
- data.tar.gz: 3d1469877613645631cfba4db32f44bd88c5c34ba988b5e6ede99397d8e802629b4fd9fac44419005e33e4e0324fa7e9f48a41b802ae7290e88db7fed58411bd
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.1.0] - 2024-08-16
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
- gem for rails apps to generate string ids with a prefix, followed by a [nanoid](https://zelark.github.io/nano-id-cc/). similar to the ids you see in stripe's api. also able to lookup any record by id, similar to rails' globalid. there's an [introductory blog post](https://schpet.com/note/cool-id) explaining why i made this.
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:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CoolId
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
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
- prefix, key = id.split(CoolId.separator, 2)
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.1
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-01-09 00:00:00.000000000 Z
11
+ date: 2025-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord