encoded_id-rails 1.0.0.rc1 → 1.0.0.rc6

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -18
  3. data/LICENSE.txt +1 -1
  4. data/README.md +76 -479
  5. data/context/encoded_id-rails.md +433 -0
  6. data/context/encoded_id.md +283 -0
  7. data/lib/encoded_id/rails/active_record_finders.rb +52 -0
  8. data/lib/encoded_id/rails/annotated_id.rb +8 -0
  9. data/lib/encoded_id/rails/annotated_id_parser.rb +8 -1
  10. data/lib/encoded_id/rails/coder.rb +20 -2
  11. data/lib/encoded_id/rails/configuration.rb +44 -4
  12. data/lib/encoded_id/rails/encoder_methods.rb +9 -1
  13. data/lib/encoded_id/rails/finder_methods.rb +10 -0
  14. data/lib/encoded_id/rails/model.rb +25 -2
  15. data/lib/encoded_id/rails/path_param.rb +7 -0
  16. data/lib/encoded_id/rails/persists.rb +52 -8
  17. data/lib/encoded_id/rails/query_methods.rb +20 -4
  18. data/lib/encoded_id/rails/railtie.rb +13 -0
  19. data/lib/encoded_id/rails/salt.rb +7 -0
  20. data/lib/encoded_id/rails/slugged_id.rb +8 -0
  21. data/lib/encoded_id/rails/slugged_id_parser.rb +8 -1
  22. data/lib/encoded_id/rails/slugged_path_param.rb +7 -0
  23. data/lib/encoded_id/rails.rb +9 -6
  24. data/lib/generators/encoded_id/rails/templates/encoded_id.rb +22 -2
  25. metadata +13 -23
  26. data/.devcontainer/Dockerfile +0 -17
  27. data/.devcontainer/compose.yml +0 -10
  28. data/.devcontainer/devcontainer.json +0 -12
  29. data/.standard.yml +0 -3
  30. data/Appraisals +0 -9
  31. data/Gemfile +0 -24
  32. data/Rakefile +0 -20
  33. data/Steepfile +0 -4
  34. data/gemfiles/.bundle/config +0 -2
  35. data/gemfiles/rails_7.2.gemfile +0 -19
  36. data/gemfiles/rails_8.0.gemfile +0 -19
  37. data/lib/encoded_id/rails/version.rb +0 -7
  38. data/rbs_collection.yaml +0 -24
  39. data/sig/encoded_id/rails.rbs +0 -141
@@ -1,11 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rbs_inline: enabled
4
+
3
5
  require "active_record"
4
6
  require "encoded_id"
5
7
 
6
8
  module EncodedId
7
9
  module Rails
8
10
  module SluggedPathParam
11
+ # Method provided by model
12
+ # @rbs!
13
+ # def slugged_encoded_id: () -> String?
14
+
15
+ # @rbs () -> String
9
16
  def to_param
10
17
  slugged_encoded_id || raise(StandardError, "Cannot create path param for #{self.class.name} without an encoded id")
11
18
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "rails/version"
3
+ # rbs_inline: enabled
4
+
4
5
  require_relative "rails/configuration"
5
6
  require_relative "rails/coder"
6
7
  require_relative "rails/slugged_id"
@@ -15,24 +16,26 @@ require_relative "rails/path_param"
15
16
  require_relative "rails/slugged_path_param"
16
17
  require_relative "rails/model"
17
18
  require_relative "rails/persists"
19
+ require_relative "rails/active_record_finders"
20
+ require_relative "rails/railtie"
18
21
 
19
22
  module EncodedId
20
23
  module Rails
21
24
  # Configuration
25
+ # @rbs self.@configuration: EncodedId::Rails::Configuration?
26
+
22
27
  class << self
28
+ # @rbs return: EncodedId::Rails::Configuration
23
29
  def configuration
24
30
  @configuration ||= Configuration.new
25
31
  end
26
32
 
33
+ # @rbs () -> EncodedId::Rails::Configuration
34
+ # | () { (EncodedId::Rails::Configuration) -> void } -> EncodedId::Rails::Configuration
27
35
  def configure
28
36
  yield(configuration) if block_given?
29
37
  configuration
30
38
  end
31
39
  end
32
40
  end
33
-
34
- # Expose directly on EncodedId
35
- Model = Rails::Model
36
- PathParam = Rails::PathParam
37
- SluggedPathParam = Rails::SluggedPathParam
38
41
  end
@@ -68,11 +68,31 @@ EncodedId::Rails.configure do |config|
68
68
  #
69
69
  # config.annotated_id_separator = "_"
70
70
 
71
- # When true, models that include EncodedId::Model will automatically have their to_param method
71
+ # When true, models that include EncodedId::Rails::Model will automatically have their to_param method
72
72
  # return the encoded ID (equivalent to also including EncodedId::Rails::PathParam).
73
- # This makes any model with EncodedId::Model automatically use encoded IDs in URLs.
73
+ # This makes any model with EncodedId::Rails::Model automatically use encoded IDs in URLs.
74
74
  #
75
75
  # Default: false
76
76
  #
77
77
  # config.model_to_param_returns_encoded_id = true
78
+
79
+ # The encoder to use for generating encoded IDs. Valid options are :hashids and :sqids.
80
+ # To use :sqids, you must add 'gem "sqids"' to your Gemfile.
81
+ #
82
+ # Default: :hashids
83
+ #
84
+ # config.encoder = :hashids
85
+
86
+ # A list of words that should not appear in generated encoded IDs.
87
+ # For the HashIds encoder, IDs containing blocklisted words will raise an error when generated.
88
+ # For the Sqids encoder, the algorithm will automatically avoid generating IDs containing these words.
89
+ # Should be an instance of EncodedId::Blocklist, or an Array or Set of strings.
90
+ #
91
+ # Default: EncodedId::Blocklist.empty
92
+ # Available built-in blocklists:
93
+ # - EncodedId::Blocklist.empty - no blocked words
94
+ # - EncodedId::Blocklist.minimal - common English profanity
95
+ # - EncodedId::Blocklist.sqids_blocklist - the default blocklist from the Sqids gem
96
+ #
97
+ # config.blocklist = EncodedId::Blocklist.minimal
78
98
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoded_id-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2025-11-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -55,14 +55,14 @@ dependencies:
55
55
  requirements:
56
56
  - - '='
57
57
  - !ruby/object:Gem::Version
58
- version: 1.0.0.rc5
58
+ version: 1.0.0.rc6
59
59
  type: :runtime
60
60
  prerelease: false
61
61
  version_requirements: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - '='
64
64
  - !ruby/object:Gem::Version
65
- version: 1.0.0.rc5
65
+ version: 1.0.0.rc6
66
66
  description: ActiveRecord concern to use EncodedID to turn IDs into reversible and
67
67
  human friendly obfuscated strings.
68
68
  email:
@@ -71,21 +71,13 @@ executables: []
71
71
  extensions: []
72
72
  extra_rdoc_files: []
73
73
  files:
74
- - ".devcontainer/Dockerfile"
75
- - ".devcontainer/compose.yml"
76
- - ".devcontainer/devcontainer.json"
77
- - ".standard.yml"
78
- - Appraisals
79
74
  - CHANGELOG.md
80
- - Gemfile
81
75
  - LICENSE.txt
82
76
  - README.md
83
- - Rakefile
84
- - Steepfile
85
- - gemfiles/.bundle/config
86
- - gemfiles/rails_7.2.gemfile
87
- - gemfiles/rails_8.0.gemfile
77
+ - context/encoded_id-rails.md
78
+ - context/encoded_id.md
88
79
  - lib/encoded_id/rails.rb
80
+ - lib/encoded_id/rails/active_record_finders.rb
89
81
  - lib/encoded_id/rails/annotated_id.rb
90
82
  - lib/encoded_id/rails/annotated_id_parser.rb
91
83
  - lib/encoded_id/rails/coder.rb
@@ -96,25 +88,23 @@ files:
96
88
  - lib/encoded_id/rails/path_param.rb
97
89
  - lib/encoded_id/rails/persists.rb
98
90
  - lib/encoded_id/rails/query_methods.rb
91
+ - lib/encoded_id/rails/railtie.rb
99
92
  - lib/encoded_id/rails/salt.rb
100
93
  - lib/encoded_id/rails/slugged_id.rb
101
94
  - lib/encoded_id/rails/slugged_id_parser.rb
102
95
  - lib/encoded_id/rails/slugged_path_param.rb
103
- - lib/encoded_id/rails/version.rb
104
96
  - lib/generators/encoded_id/rails/USAGE
105
97
  - lib/generators/encoded_id/rails/add_columns_generator.rb
106
98
  - lib/generators/encoded_id/rails/install_generator.rb
107
99
  - lib/generators/encoded_id/rails/templates/add_encoded_id_columns_migration.rb.erb
108
100
  - lib/generators/encoded_id/rails/templates/encoded_id.rb
109
- - rbs_collection.yaml
110
- - sig/encoded_id/rails.rbs
111
- homepage: https://github.com/stevegeek/encoded_id-rails
101
+ homepage: https://github.com/stevegeek/encoded_id
112
102
  licenses:
113
103
  - MIT
114
104
  metadata:
115
- homepage_uri: https://github.com/stevegeek/encoded_id-rails
116
- source_code_uri: https://github.com/stevegeek/encoded_id-rails
117
- changelog_uri: https://github.com/stevegeek/encoded_id-rails/blob/master/CHANGELOG.md
105
+ homepage_uri: https://github.com/stevegeek/encoded_id
106
+ source_code_uri: https://github.com/stevegeek/encoded_id
107
+ changelog_uri: https://github.com/stevegeek/encoded_id/blob/main/CHANGELOG.md
118
108
  rdoc_options: []
119
109
  require_paths:
120
110
  - lib
@@ -129,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
119
  - !ruby/object:Gem::Version
130
120
  version: '0'
131
121
  requirements: []
132
- rubygems_version: 3.6.7
122
+ rubygems_version: 3.6.2
133
123
  specification_version: 4
134
124
  summary: Use `encoded_id` with ActiveRecord models
135
125
  test_files: []
@@ -1,17 +0,0 @@
1
- # Make sure RUBY_VERSION matches the Ruby version in .ruby-version or gemspec
2
- ARG RUBY_VERSION=3.4.2
3
- FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION
4
-
5
- USER root
6
-
7
- # Install pkg-config and SQLite development libraries
8
- RUN apt-get update -qq && \
9
- apt-get install -y pkg-config libsqlite3-dev && \
10
- apt-get clean && \
11
- rm -rf /var/lib/apt/lists/*
12
-
13
- USER vscode
14
-
15
- # Ensure binding is always 0.0.0.0
16
- # Binds the server to all IP addresses of the container, so it can be accessed from outside the container.
17
- ENV BINDING="0.0.0.0"
@@ -1,10 +0,0 @@
1
- name: "encoded_id-rails"
2
-
3
- services:
4
- encoded-id-rails-dev-env:
5
- container_name: encoded-id-rails-dev-env
6
- build:
7
- context: ..
8
- dockerfile: .devcontainer/Dockerfile
9
- ports:
10
- - "3000"
@@ -1,12 +0,0 @@
1
- {
2
- "name": "Encoded ID Rails Gem Development",
3
- "dockerComposeFile": "compose.yml",
4
- "service": "encoded-id-rails-dev-env",
5
- "containerEnv": {
6
- "RAILS_ENV": "development"
7
- },
8
- "forwardPorts": [3000],
9
- "postCreateCommand": "bundle install && bundle exec appraisal install",
10
- "postStartCommand": "bundle exec rake test",
11
- "remoteUser": "vscode"
12
- }
data/.standard.yml DELETED
@@ -1,3 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/testdouble/standard
3
- ruby_version: 2.6
data/Appraisals DELETED
@@ -1,9 +0,0 @@
1
- appraise "rails-7.2" do
2
- gem "activesupport", "~> 7.2.0"
3
- gem "activerecord", "~> 7.2.0"
4
- end
5
-
6
- appraise "rails-8.0" do
7
- gem "activesupport", "~> 8.0.0"
8
- gem "activerecord", "~> 8.0.0"
9
- end
data/Gemfile DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in encoded_id-rails.gemspec
6
- gemspec
7
-
8
- group :development, :test do
9
- gem "rake", "~> 13.0"
10
-
11
- gem "minitest", "~> 5.0"
12
-
13
- gem "standard", "~> 1.30"
14
-
15
- gem "steep", "~> 1.5"
16
-
17
- gem "rails"
18
-
19
- gem "sqlite3"
20
-
21
- gem "appraisal"
22
-
23
- gem "simplecov"
24
- end
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- desc "Run tests with coverage"
13
- task :coverage do
14
- ENV["COVERAGE"] = "true"
15
- Rake::Task["test"].invoke
16
- end
17
-
18
- require "standard/rake"
19
-
20
- task default: %i[test standard]
data/Steepfile DELETED
@@ -1,4 +0,0 @@
1
- target :lib do
2
- check "lib/encoded_id"
3
- signature "sig"
4
- end
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_RETRY: "1"
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 7.2.0"
6
- gem "activerecord", "~> 7.2.0"
7
-
8
- group :development, :test do
9
- gem "rake", "~> 13.0"
10
- gem "minitest", "~> 5.0"
11
- gem "standard", "~> 1.30"
12
- gem "steep", "~> 1.5"
13
- gem "rails"
14
- gem "sqlite3"
15
- gem "appraisal"
16
- gem "simplecov"
17
- end
18
-
19
- gemspec path: "../"
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 8.0.0"
6
- gem "activerecord", "~> 8.0.0"
7
-
8
- group :development, :test do
9
- gem "rake", "~> 13.0"
10
- gem "minitest", "~> 5.0"
11
- gem "standard", "~> 1.30"
12
- gem "steep", "~> 1.5"
13
- gem "rails"
14
- gem "sqlite3"
15
- gem "appraisal"
16
- gem "simplecov"
17
- end
18
-
19
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EncodedId
4
- module Rails
5
- VERSION = "1.0.0.rc1"
6
- end
7
- end
data/rbs_collection.yaml DELETED
@@ -1,24 +0,0 @@
1
- # Download sources
2
- sources:
3
- - name: ruby/gem_rbs_collection
4
- remote: https://github.com/ruby/gem_rbs_collection.git
5
- revision: main
6
- repo_dir: gems
7
-
8
- # A directory to install the downloaded RBSs
9
- path: .gem_rbs_collection
10
-
11
- gems:
12
- - name: cgi
13
- # Skip loading rbs gem's RBS.
14
- # It's unnecessary if you don't use rbs as a library.
15
- - name: rbs
16
- ignore: true
17
- - name: rake
18
- ignore: true
19
- - name: minitest
20
- ignore: true
21
- - name: standard
22
- ignore: true
23
- - name: steep
24
- ignore: true
@@ -1,141 +0,0 @@
1
- module EncodedId
2
- module Rails
3
- VERSION: ::String
4
-
5
- class Configuration
6
- attr_accessor salt: ::String
7
- attr_accessor group_separator: ::String
8
- attr_accessor character_group_size: ::Integer
9
- attr_accessor alphabet: ::EncodedId::Alphabet
10
- attr_accessor id_length: ::Integer
11
- attr_accessor slug_method_name: ::Symbol
12
- attr_accessor slugged_id_separator: ::String
13
- attr_accessor annotation_method_name: ::Symbol
14
- attr_accessor annotated_id_separator: ::String
15
-
16
- def initialize: () -> void
17
- end
18
-
19
- attr_reader self.configuration: Configuration
20
-
21
- def self.configure: () { (Configuration config) -> void } -> void
22
-
23
- class Coder
24
- def initialize: (salt: ::String, id_length: ::Integer, character_group_size: ::Integer, separator: ::String, alphabet: ::EncodedId::Alphabet) -> void
25
- def encode: (::Integer | ::Array[::Integer]) -> String
26
- def decode: (::String) -> ::Array[::Integer]?
27
-
28
- @salt: ::String
29
- @id_length: ::Integer
30
- @character_group_size: ::Integer
31
- @separator: ::String
32
- @alphabet: ::EncodedId::Alphabet
33
-
34
- private
35
-
36
- def coder: -> ::EncodedId::ReversibleId
37
- end
38
-
39
- class Salt
40
- def initialize: (Class klass, ::String salt) -> void
41
-
42
- @klass: Class
43
- @salt: ::String
44
-
45
- def generate!: -> ::String
46
- end
47
-
48
- class SluggedId
49
- def initialize: (slug_part: ::String, id_part: ::String, ?separator: ::String)-> void
50
- @slug_part: ::String
51
- @id_part: ::String
52
- @separator: ::String
53
-
54
- def slugged_id: -> ::String
55
- end
56
-
57
- class AnnotatedId
58
- def initialize: (annotation: ::String, id_part: ::String, ?separator: ::String)-> void
59
- @annotation: ::String
60
- @id_part: ::String
61
- @separator: ::String
62
-
63
- def annotated_id: -> ::String
64
- end
65
-
66
- class SluggedIdParser
67
- def initialize: (::String slugged_id, ?separator: ::String) -> void
68
-
69
- attr_reader slug: ::String?
70
- attr_reader id: ::String
71
- end
72
-
73
- class AnnotatedIdParser
74
- def initialize: (::String annotated_id, ?separator: ::String) -> void
75
-
76
- attr_reader annotation: ::String?
77
- attr_reader id: ::String
78
- end
79
-
80
- module EncoderMethods
81
- def encode_encoded_id: (::Array[::Integer] | ::Integer id, ?::Hash[::Symbol, untyped] options) -> ::String
82
- def decode_encoded_id: (::String slugged_encoded_id, ?::Hash[::Symbol, untyped] options) -> ::Array[::Integer]?
83
- def encoded_id_salt: () -> ::String
84
- def encoded_id_coder: (?::Hash[::Symbol, untyped] options) -> ::EncodedId::Rails::Coder
85
- end
86
-
87
- interface _ActiveRecordFinderMethod
88
- def find_by: (*untyped) -> (nil | untyped)
89
- end
90
-
91
- module FinderMethods : EncoderMethods, _ActiveRecordFinderMethod, _ActiveRecordQueryMethod
92
- def find_by_encoded_id: (::String encoded_id, ?with_id: ::Symbol?) -> untyped?
93
- def find_by_encoded_id!: (::String encoded_id, ?with_id: ::Symbol?) -> untyped
94
- def find_all_by_encoded_id: (::String encoded_id) -> untyped?
95
- def find_all_by_encoded_id!: (::String encoded_id) -> untyped
96
- end
97
-
98
- interface _ActiveRecordQueryMethod
99
- def where: (*untyped) -> untyped
100
- end
101
-
102
- module QueryMethods : EncoderMethods, _ActiveRecordQueryMethod
103
- def where_encoded_id: (::String slugged_encoded_id) -> untyped
104
- end
105
-
106
- module Model : ActiveRecord::Base
107
- # From ActiveRecord
108
- extend ActiveRecord::FinderMethods
109
- extend ActiveRecord::QueryMethods
110
- def id_changed?: -> bool
111
-
112
- # From EncodedId::Rails::Model
113
- extend EncoderMethods
114
- extend FinderMethods
115
- extend QueryMethods
116
-
117
- @encoded_id: ::String
118
- @slugged_encoded_id: ::String
119
-
120
- def encoded_id_hash: -> ::String?
121
- def encoded_id: -> ::String?
122
- def slugged_encoded_id: -> ::String?
123
- def name_for_encoded_id_slug: -> ::String
124
- def annotation_for_encoded_id: -> ::String
125
- end
126
-
127
- interface _ActiveRecordToParam
128
- def to_param: -> ::String
129
- end
130
-
131
- module PathParam : Model, _ActiveRecordToParam
132
- end
133
-
134
- module SluggedPathParam : Model, _ActiveRecordToParam
135
- end
136
- end
137
-
138
- Model: singleton(Rails::Model)
139
- PathParam: singleton(Rails::PathParam)
140
- SluggedPathParam: singleton(Rails::SluggedPathParam)
141
- end