encoded_id 1.0.0.rc6 → 1.0.0.rc7

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.
metadata CHANGED
@@ -1,19 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoded_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc6
4
+ version: 1.0.0.rc7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-17 00:00:00.000000000 Z
11
- dependencies: []
10
+ date: 2025-11-20 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: sqids
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.2'
12
26
  description: Encode your numerical IDs (eg record primary keys) into obfuscated strings
13
27
  that can be used in URLs. The obfuscated strings are reversible, so you can decode
14
28
  them back into the original numerical IDs. Supports encoding multiple IDs at once,
15
29
  and generating IDs with custom alphabets and separators to make the IDs easier to
16
- read or share. Dependency free.
30
+ read or share. Uses Sqids by default, with HashIds as an alternative.
17
31
  email:
18
32
  - stevegeek@gmail.com
19
33
  executables: []
@@ -27,13 +41,16 @@ files:
27
41
  - lib/encoded_id.rb
28
42
  - lib/encoded_id/alphabet.rb
29
43
  - lib/encoded_id/blocklist.rb
30
- - lib/encoded_id/encoders/base.rb
31
- - lib/encoded_id/encoders/hash_id.rb
32
- - lib/encoded_id/encoders/hash_id_consistent_shuffle.rb
33
- - lib/encoded_id/encoders/hash_id_ordinal_alphabet_separator_guards.rb
34
- - lib/encoded_id/encoders/hash_id_salt.rb
44
+ - lib/encoded_id/encoders/base_configuration.rb
45
+ - lib/encoded_id/encoders/hashid.rb
46
+ - lib/encoded_id/encoders/hashid_configuration.rb
47
+ - lib/encoded_id/encoders/hashid_consistent_shuffle.rb
48
+ - lib/encoded_id/encoders/hashid_ordinal_alphabet_separator_guards.rb
49
+ - lib/encoded_id/encoders/hashid_salt.rb
35
50
  - lib/encoded_id/encoders/my_sqids.rb
36
51
  - lib/encoded_id/encoders/sqids.rb
52
+ - lib/encoded_id/encoders/sqids_configuration.rb
53
+ - lib/encoded_id/encoders/sqids_with_blocklist_mode.rb
37
54
  - lib/encoded_id/hex_representation.rb
38
55
  - lib/encoded_id/reversible_id.rb
39
56
  - lib/encoded_id/version.rb
@@ -61,5 +78,5 @@ requirements: []
61
78
  rubygems_version: 3.6.2
62
79
  specification_version: 4
63
80
  summary: EncodedId is a gem for creating reversible obfuscated IDs from numerical
64
- IDs. It uses an implementation of Hash IDs under the hood.
81
+ IDs. It uses Sqids by default.
65
82
  test_files: []
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # rbs_inline: enabled
4
-
5
- module EncodedId
6
- module Encoders
7
- class Base
8
- # @rbs @min_hash_length: Integer
9
- # @rbs @alphabet: Alphabet
10
- # @rbs @salt: String
11
- # @rbs @blocklist: Blocklist
12
-
13
- # @rbs (String salt, ?Integer min_hash_length, ?Alphabet alphabet, ?Blocklist blocklist) -> void
14
- def initialize(salt, min_hash_length = 0, alphabet = Alphabet.alphanum, blocklist = Blocklist.empty)
15
- @min_hash_length = min_hash_length
16
- @alphabet = alphabet
17
- @salt = salt
18
- @blocklist = blocklist
19
- end
20
-
21
- attr_reader :min_hash_length #: Integer
22
- attr_reader :alphabet #: Alphabet
23
- attr_reader :salt #: String
24
- attr_reader :blocklist #: Blocklist
25
-
26
- # Encode array of numbers into a string
27
- # @rbs (Array[Integer] numbers) -> String
28
- def encode(numbers)
29
- raise NotImplementedError, "#{self.class} must implement #encode"
30
- end
31
-
32
- # Encode hexadecimal string(s) into a string
33
- # @rbs (String str) -> String
34
- def encode_hex(str)
35
- return "" unless hex_string?(str)
36
-
37
- numbers = str.scan(/[\w\W]{1,12}/).map do |num|
38
- "1#{num}".to_i(16)
39
- end
40
-
41
- encode(numbers)
42
- end
43
-
44
- # Decode a string back into an array of numbers
45
- # @rbs (String hash) -> Array[Integer]
46
- def decode(hash)
47
- raise NotImplementedError, "#{self.class} must implement #decode"
48
- end
49
-
50
- # Decode a string back into an array of hexadecimal strings
51
- # @rbs (String hash) -> String
52
- def decode_hex(hash)
53
- numbers = decode(hash)
54
- return "" if numbers.empty?
55
-
56
- ret = numbers.map do |n|
57
- n.to_s(16)[1..]
58
- end
59
-
60
- ret.join.upcase
61
- end
62
-
63
- private
64
-
65
- # @rbs (String string) -> MatchData?
66
- def hex_string?(string)
67
- string.to_s.match(/\A[0-9a-fA-F]+\Z/)
68
- end
69
- end
70
- end
71
- end