encoded_id 1.0.0.rc7 → 1.0.0

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: c94c4fae6354b78328fed94361c666d7df2cf7e797cd1523db2db6e7a57e3d81
4
- data.tar.gz: d65c032660d6894da1c81bec5156a9f733ea02d56631b6cc199ed82dcdd1eb24
3
+ metadata.gz: ccfa7987d3a108bfce0268467b8ae40793226e98f01fa2c331bc1f642026f47b
4
+ data.tar.gz: b4cb2429a8031f0e576f242550397b4683e302a184d57f0c85b870da502e181e
5
5
  SHA512:
6
- metadata.gz: 6c6a510d660bc34709dc4442dcfd14d63320b79b79f595de8dea225d21379cd859d7473ecab83e137c557fca0f3bf3ceaf0c3074efe98434c5743bb3d0d8387a
7
- data.tar.gz: f7724cf6109b4dfd25729bf7c974c496864525e46de58141bba0bf74ae69ce165d8c6549a6a0ab23325dd0c0fbd6386d40815573be3cfc5ca59dd3fa50a83dc6
6
+ metadata.gz: db4ae0c6d8477ea3ab5ada1bcbd959b18420c1aa1be54ec747898d298f16e6dd6a2090ff4a18008fe1711d3641c158bf9a8c1da23a33663be7fbc17a68079409
7
+ data.tar.gz: 4e731df7f992cf6935012cabffc7c6d4923de5db46059c123780d0f6a1dfbe329844ddf074580c67ec1a16101afb9c315175049045bcf5375e6666ae2707fa0b
data/CHANGELOG.md CHANGED
@@ -2,12 +2,17 @@
2
2
 
3
3
  - nothing yet
4
4
 
5
- ## [1.0.0] - unreleased
5
+ ## [1.0.0] - 2025-11-21
6
6
 
7
7
  - First stable release!
8
8
 
9
9
  **Important!!: `:sqids` are not compatible with `:hashids`, DO NOT CHANGE FROM ONE TO THE OTHER AFTER GOING LIVE.**
10
10
 
11
+ ### Fixed (Rails integration)
12
+
13
+ - Ensure finder methods correctly override their ActiveRecord counterparts
14
+ - Warn when ActiveRecord integration used in model that doesn't use `id` as primary key
15
+
11
16
  ## [1.0.0.rc7] - 2025-11-19
12
17
 
13
18
  ### Breaking changes
@@ -7,20 +7,16 @@ module EncodedId
7
7
  # Base configuration class for encoder-specific settings
8
8
  # This provides common parameters shared across all encoders
9
9
  class BaseConfiguration
10
- # @rbs @min_length: Integer
11
- # @rbs @alphabet: Alphabet
12
- # @rbs @split_at: Integer?
13
- # @rbs @split_with: String?
14
- # @rbs @hex_digit_encoding_group_size: Integer
15
- # @rbs @max_length: Integer?
16
- # @rbs @max_inputs_per_id: Integer
17
- # @rbs @blocklist: Blocklist
18
- # @rbs @blocklist_mode: Symbol
19
- # @rbs @blocklist_max_length: Integer
20
-
21
- attr_reader :min_length, :alphabet, :split_at, :split_with,
22
- :hex_digit_encoding_group_size, :max_length,
23
- :max_inputs_per_id, :blocklist, :blocklist_mode, :blocklist_max_length
10
+ attr_reader :min_length #: Integer
11
+ attr_reader :alphabet #: Alphabet
12
+ attr_reader :split_at #: Integer?
13
+ attr_reader :split_with #: String?
14
+ attr_reader :hex_digit_encoding_group_size #: Integer
15
+ attr_reader :max_length #: Integer?
16
+ attr_reader :max_inputs_per_id #: Integer
17
+ attr_reader :blocklist #: Blocklist
18
+ attr_reader :blocklist_mode #: Symbol
19
+ attr_reader :blocklist_max_length #: Integer
24
20
 
25
21
  # @rbs (?min_length: Integer, ?alphabet: Alphabet, ?split_at: Integer?, ?split_with: String?, ?hex_digit_encoding_group_size: Integer, ?max_length: Integer?, ?max_inputs_per_id: Integer, ?blocklist: Blocklist | Array[String] | Set[String] | nil, ?blocklist_mode: Symbol, ?blocklist_max_length: Integer) -> void
26
22
  def initialize(
@@ -49,12 +45,7 @@ module EncodedId
49
45
  validate_blocklist_collision_risk
50
46
  end
51
47
 
52
- # @rbs () -> Symbol
53
- def encoder_type
54
- raise NotImplementedError, "Subclasses must implement encoder_type"
55
- end
56
-
57
- # @rbs () -> untyped
48
+ # @rbs () -> (Hashid | Sqids)
58
49
  def create_encoder
59
50
  raise NotImplementedError, "Subclasses must implement create_encoder"
60
51
  end
@@ -7,9 +7,7 @@ module EncodedId
7
7
  # Configuration for Hashids encoder
8
8
  # Hashids requires a salt for encoding/decoding
9
9
  class HashidConfiguration < BaseConfiguration
10
- # @rbs @salt: String
11
-
12
- attr_reader :salt
10
+ attr_reader :salt #: String
13
11
 
14
12
  # @rbs (salt: String, **untyped options) -> void
15
13
  def initialize(salt:, **options)
@@ -17,11 +15,6 @@ module EncodedId
17
15
  super(**options)
18
16
  end
19
17
 
20
- # @rbs () -> Symbol
21
- def encoder_type
22
- :hashids
23
- end
24
-
25
18
  # Create the Hashid encoder instance
26
19
  # @rbs () -> Hashid
27
20
  def create_encoder
@@ -6,10 +6,7 @@ module EncodedId
6
6
  module Encoders
7
7
  # Encoder implementation using the Sqids algorithm for encoding/decoding IDs.
8
8
  class Sqids
9
- # @rbs @sqids: untyped
10
- # @rbs @min_hash_length: Integer
11
- # @rbs @alphabet: Alphabet
12
- # @rbs @blocklist: Blocklist
9
+ # @rbs @sqids: SqidsWithBlocklistMode
13
10
  # @rbs @blocklist_mode: Symbol
14
11
  # @rbs @blocklist_max_length: Integer
15
12
 
@@ -7,11 +7,6 @@ module EncodedId
7
7
  # Configuration for Sqids encoder
8
8
  # Sqids does not use a salt - it shuffles the alphabet deterministically
9
9
  class SqidsConfiguration < BaseConfiguration
10
- # @rbs () -> Symbol
11
- def encoder_type
12
- :sqids
13
- end
14
-
15
10
  # Create the Sqids encoder instance
16
11
  # @rbs () -> Sqids
17
12
  def create_encoder
@@ -44,10 +44,8 @@ class SqidsWithBlocklistMode < MySqids
44
44
  true
45
45
  when :length_threshold
46
46
  id.length <= @blocklist_max_length
47
- when :raise_if_likely
48
- # This mode raises at configuration time, so if we get here, we check
49
- true
50
47
  else
48
+ # If :raise_if_likely mode it raises at configuration time, so if we get here, we check
51
49
  true
52
50
  end
53
51
  end
@@ -10,10 +10,6 @@ module EncodedId
10
10
  # type encodeableValue = Array[String | Integer] | String | Integer
11
11
 
12
12
  class ReversibleId
13
- # @rbs @config: Encoders::BaseConfiguration
14
- # @rbs @hex_represention_encoder: HexRepresentation
15
- # @rbs @encoder: untyped
16
-
17
13
  # Factory method to create a Hashid-based reversible ID
18
14
  # @rbs (salt: String, **untyped options) -> ReversibleId
19
15
  def self.hashid(salt:, **options)
@@ -40,40 +36,13 @@ module EncodedId
40
36
  @encoder = create_encoder
41
37
  end
42
38
 
43
- # @rbs () -> String?
44
- def salt
45
- config = @config
46
- return config.salt if config.is_a?(Encoders::HashidConfiguration)
47
- nil
48
- end
49
-
50
- def min_length
51
- @config.min_length
52
- end
53
-
54
- def alphabet
55
- @config.alphabet
56
- end
57
-
58
- def split_at
59
- @config.split_at
60
- end
61
-
62
- def split_with
63
- @config.split_with
64
- end
65
-
66
- attr_reader :hex_represention_encoder
67
-
68
- def max_length
69
- @config.max_length
70
- end
71
-
72
- def blocklist
73
- @config.blocklist
74
- end
39
+ # The configuration object for this encoder instance.
40
+ # Returns either an Encoders::HashidConfiguration or Encoders::SqidsConfiguration.
41
+ # Useful for introspecting settings like alphabet, min_length, blocklist, etc.
42
+ attr_reader :config #: Encoders::BaseConfiguration
75
43
 
76
- attr_reader :encoder #: untyped
44
+ attr_reader :hex_represention_encoder #: HexRepresentation
45
+ attr_reader :encoder #: Encoders::Hashid | Encoders::Sqids
77
46
 
78
47
  # Encode the input values into a hash
79
48
  # @rbs (encodeableValue values) -> String
@@ -122,7 +91,7 @@ module EncodedId
122
91
  inputs
123
92
  end
124
93
 
125
- # @rbs () -> untyped
94
+ # @rbs () -> (Encoders::Hashid | Encoders::Sqids)
126
95
  def create_encoder
127
96
  @config.create_encoder
128
97
  end
@@ -150,7 +119,8 @@ module EncodedId
150
119
  # Reverses humanize_length transformation: removes separators and optionally downcases
151
120
  # @rbs (String str, bool downcase) -> String
152
121
  def convert_to_hash(str, downcase)
153
- str = str.gsub(@config.split_with, "") if @config.split_with
122
+ split_with = @config.split_with
123
+ str = str.gsub(split_with, "") if split_with
154
124
  str = str.downcase if downcase
155
125
  map_equivalent_characters(str)
156
126
  end
@@ -169,9 +139,10 @@ module EncodedId
169
139
 
170
140
  # @rbs (String str) -> bool
171
141
  def max_length_exceeded?(str)
172
- return false if @config.max_length.nil?
142
+ max_len = @config.max_length
143
+ return false unless max_len
173
144
 
174
- str.length > @config.max_length
145
+ str.length > max_len
175
146
  end
176
147
  end
177
148
  end
@@ -3,5 +3,5 @@
3
3
  # rbs_inline: enabled
4
4
 
5
5
  module EncodedId
6
- VERSION = "1.0.0.rc7"
6
+ VERSION = "1.0.0"
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoded_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-20 00:00:00.000000000 Z
10
+ date: 2025-11-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: sqids