cool_id 0.1.6 → 0.1.7

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: 0d44c3207248595af232a200cf0e809224d74033d97d3cac52c6d06d5416b682
4
- data.tar.gz: d221baeb8e79ea8ea8ca2b9503685e4bfa7cb8d57b53a3ba0e4d301138a08300
3
+ metadata.gz: cd52ffe11cf7b25bf473b06e879a7df67eb4aea3b9169b0961342fef30a6fce7
4
+ data.tar.gz: b92c14dd88880ad52de1884f8a1e2720915b5ee24b742c0db8a966071bd07196
5
5
  SHA512:
6
- metadata.gz: 9ed700560671d811b0678c4fbe8f9e086c3ca0c9e8d04a54b7d40d586b20864e2add65adb9e5e53feb7915e472974dbfa6b31313dd6a64f4008aaf3f31503f70
7
- data.tar.gz: df1cdc3098d9b4761a220fedeca362eeaeb5677d92ca7da594dc946223d814c81bb59db757ff08292fe72e3ce499dd95e1cc002ccf27c436aa097617bd14f2a9
6
+ metadata.gz: f41bf3c022796fdaf4e8f53af035b6515c6a6b5ac59b749c52a17247bb6710b7296424d2a86c20f484500cae15f7daec32ec1a3980717441a0fec186ad528945
7
+ data.tar.gz: c81557d5b123b122be77208ef6c74421d81c048dd409f289421ee1bfbaea075550621c77d0c6d92f5b11df393b4fd3be820e62cf2ef491a8e48958705e218d5c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # cool_id
1
+ # cool id
2
2
 
3
- a gem for rails that generates string primary key ids for active record models with a per-model prefix followed by a nanoid. this lets you create stripe style ids in your own rails app, and they'll be the same ids you see in your database.
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
- it can also lookup records similar to global id:
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
- ### using cool_id in one model
75
+ ### adding cool_id to a single model
76
76
 
77
77
  use string ids when creating a table
78
78
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CoolId
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
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 Error < StandardError; end
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 skip_enforce_cool_id_for_descendants
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
- raise Error, "CoolId not configured for #{self.class}. Use 'cool_id' to configure or 'skip_enforce_cool_id_for_descendants' to opt out."
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.6
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-18 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nanoid