cool_id 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/cool_id/version.rb +1 -1
- data/lib/cool_id.rb +4 -3
- 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: cd52ffe11cf7b25bf473b06e879a7df67eb4aea3b9169b0961342fef30a6fce7
|
4
|
+
data.tar.gz: b92c14dd88880ad52de1884f8a1e2720915b5ee24b742c0db8a966071bd07196
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41bf3c022796fdaf4e8f53af035b6515c6a6b5ac59b749c52a17247bb6710b7296424d2a86c20f484500cae15f7daec32ec1a3980717441a0fec186ad528945
|
7
|
+
data.tar.gz: c81557d5b123b122be77208ef6c74421d81c048dd409f289421ee1bfbaea075550621c77d0c6d92f5b11df393b4fd3be820e62cf2ef491a8e48958705e218d5c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# cool id
|
2
2
|
|
3
|
-
|
3
|
+
gem for rails apps to generates 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.
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
class User < ActiveRecord::Base
|
@@ -12,7 +12,7 @@ User.create!(name: "...").id
|
|
12
12
|
# => "usr_vktd1b5v84lr"
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
lookup any record by its id
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
CoolId.locate("usr_vktd1b5v84lr")
|
@@ -72,7 +72,7 @@ bundle add cool_id
|
|
72
72
|
gem "cool_id"
|
73
73
|
```
|
74
74
|
|
75
|
-
###
|
75
|
+
### adding cool_id to a single model
|
76
76
|
|
77
77
|
use string ids when creating a table
|
78
78
|
|
data/lib/cool_id/version.rb
CHANGED
data/lib/cool_id.rb
CHANGED
@@ -5,7 +5,7 @@ require "nanoid"
|
|
5
5
|
require "active_support/concern"
|
6
6
|
|
7
7
|
module CoolId
|
8
|
-
class
|
8
|
+
class NotConfiguredError < StandardError; end
|
9
9
|
|
10
10
|
# defaults based on https://planetscale.com/blog/why-we-chose-nanoids-for-planetscales-api
|
11
11
|
DEFAULT_SEPARATOR = "_"
|
@@ -110,7 +110,7 @@ module CoolId
|
|
110
110
|
@cool_id_setup_required = true
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def skip_enforce_cool_id
|
114
114
|
@cool_id_setup_required = false
|
115
115
|
end
|
116
116
|
|
@@ -134,7 +134,8 @@ module CoolId
|
|
134
134
|
|
135
135
|
def ensure_cool_id_configured
|
136
136
|
if self.class.cool_id_setup_required && self.class.cool_id_config.nil?
|
137
|
-
|
137
|
+
suggested_prefix = self.class.name.downcase[0..2]
|
138
|
+
raise NotConfiguredError, "CoolId not configured for #{self.class}. Use 'cool_id' to configure or 'skip_enforce_cool_id' to opt out.\n\ne.g.\n\nclass #{self.class} < ApplicationRecord\n cool_id prefix: \"#{suggested_prefix}\"\nend"
|
138
139
|
end
|
139
140
|
end
|
140
141
|
end
|
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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Schilling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nanoid
|