cool_id 0.2.3 → 0.2.5

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: d21dfe6f7e0ba866d387136fd73f24bbf8645c6aeb939a9e0a74bfa1d3cacd68
4
- data.tar.gz: 8657776cd68fcd3e97612f024f78f3c1f22a161c98ac0eb61456f077bd818e7c
3
+ metadata.gz: 2f9afbdd3fb7f6f3ede4f68bc32951170f3c912703f4b6cc76cea7570cd6b180
4
+ data.tar.gz: 37b6adbec540280b477be327a50354ddc06089e445256c30e1a1001077984c6d
5
5
  SHA512:
6
- metadata.gz: c01f20fbeb0475a5462667c76645f9d16c35a04d3751cb6594951c5694e0b1d7ac7cb0f4b2dced316be490686d8590c96b33c10841efcffb0ccd3bc84fc60a24
7
- data.tar.gz: 0d089f99a4f74f3ff709f025fbfa0779b12d3fc028b1c192948534e33a0623f134cadb580d06507ef6e7474242e719e1329641f5741c11e28a9e270e18015fcc
6
+ metadata.gz: 146d6df59c6f6cdd9094b51d5780d268d0a051232baf7be767909b5acfdb239b6b4cf2238ca62318ef20442bd68a7a0e0321ec87e992e22ee8633f043c3796a9
7
+ data.tar.gz: 53b5eae24c6fb645dd614381e2b75a7c509d58339846a8148e1405ab0d14f14f696001805a086957b64756cb4983e6a3b93de3acbea3d86cd192821db9df593f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.5] - 2026-01-07
6
+
7
+ ### Fixed
8
+
9
+ - duplicate prefix error when Rails reloads model classes in development mode
10
+
11
+ ## [0.2.4] - 2025-12-18
12
+
13
+ ### Fixed
14
+
15
+ - raise an error if a prefix is registered more than once
16
+
5
17
  ## [0.2.3] - 2025-05-29
6
18
 
7
19
  ### Fixed
@@ -32,7 +44,9 @@
32
44
 
33
45
  - Initial release
34
46
 
35
- [Unreleased]: https://github.com/schpet/cool_id/compare/v0.2.3...HEAD
47
+ [Unreleased]: https://github.com/schpet/cool_id/compare/v0.2.5...HEAD
48
+ [0.2.5]: https://github.com/schpet/cool_id/compare/v0.2.4...v0.2.5
49
+ [0.2.4]: https://github.com/schpet/cool_id/compare/v0.2.3...v0.2.4
36
50
  [0.2.3]: https://github.com/schpet/cool_id/compare/v0.2.2...v0.2.3
37
51
  [0.2.2]: https://github.com/schpet/cool_id/compare/v0.2.1...v0.2.2
38
52
  [0.2.1]: https://github.com/schpet/cool_id/compare/v0.2.0...v0.2.1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CoolId
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.5"
5
5
  end
data/lib/cool_id.rb CHANGED
@@ -12,6 +12,9 @@ module CoolId
12
12
  # Error raised when the maximum number of retries is exceeded while generating a unique ID.
13
13
  class MaxRetriesExceededError < StandardError; end
14
14
 
15
+ # Error raised when a prefix is already registered to another model.
16
+ class DuplicatePrefixError < StandardError; end
17
+
15
18
  # Default separator used in generated IDs.
16
19
  DEFAULT_SEPARATOR = "_"
17
20
 
@@ -114,7 +117,19 @@ module CoolId
114
117
  # @param prefix [String] The prefix to register.
115
118
  # @param model_class [Class] The ActiveRecord model class to associate with the prefix.
116
119
  # @return [void]
120
+ # @raise [DuplicatePrefixError] If the prefix is already registered to a different model.
117
121
  def register(prefix, model_class)
122
+ existing = @prefix_map[prefix]
123
+ if existing
124
+ same_class = if existing.name && model_class.name
125
+ existing.name == model_class.name
126
+ else
127
+ existing == model_class
128
+ end
129
+ unless same_class
130
+ raise DuplicatePrefixError, "Prefix '#{prefix}' is already registered to #{existing.name}"
131
+ end
132
+ end
118
133
  @prefix_map[prefix] = model_class
119
134
  end
120
135
 
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.3
4
+ version: 0.2.5
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-05-29 00:00:00.000000000 Z
11
+ date: 2026-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord