opaque_id 1.4.0 → 1.7.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.
@@ -1,110 +0,0 @@
1
- This is the original functionality we are replicating and enhancing. typically implemented as a concern in a Model via `include Identifiable`
2
-
3
- ```ruby
4
- require "nanoid"
5
-
6
- # generate a public_id (nanoid) when creating new records
7
- # unique URL-friendly ID that'll prevent exposing incremental db ids where
8
- # we otherwise can't or don't want to use friendly_ids e.g. in URLs and APIs
9
- #
10
- # https://planetscale.com/blog/why-we-chose-nanoids-for-planetscales-api#generating-nanoids-in-rails
11
- # https://maful.web.id/posts/how-i-use-nano-id-in-rails/
12
- # https://zelark.github.io/nano-id-cc/
13
- module Identifiable
14
- extend ActiveSupport::Concern
15
-
16
- included do
17
- before_create :set_public_id
18
- end
19
-
20
- PUBLIC_ID_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"
21
- PUBLIC_ID_LENGTH = 18
22
- MAX_RETRY = 1000
23
-
24
- PUBLIC_ID_REGEX = /[#{PUBLIC_ID_ALPHABET}]{#{PUBLIC_ID_LENGTH}}\z/
25
-
26
- class_methods do
27
- def generate_nanoid(alphabet: PUBLIC_ID_ALPHABET, size: PUBLIC_ID_LENGTH)
28
- Nanoid.generate(size:, alphabet:)
29
- end
30
- end
31
-
32
- def set_public_id
33
- return if public_id.present?
34
-
35
- MAX_RETRY.times do
36
- self.public_id = generate_public_id
37
- return unless self.class.where(public_id:).exists?
38
- end
39
- raise "Failed to generate a unique public id after #{MAX_RETRY} attempts"
40
- end
41
-
42
- def generate_public_id
43
- self.class.generate_nanoid(alphabet: PUBLIC_ID_ALPHABET)
44
- end
45
- end
46
- ```
47
-
48
- The original nanoid.rb is below
49
-
50
- ```ruby
51
- require 'securerandom'
52
-
53
- module Nanoid
54
- SAFE_ALPHABET = '_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.freeze
55
-
56
- def self.generate(size: 21, alphabet: SAFE_ALPHABET, non_secure: false)
57
- return non_secure_generate(size: size, alphabet: alphabet) if non_secure
58
-
59
- return simple_generate(size: size) if alphabet == SAFE_ALPHABET
60
-
61
- complex_generate(size: size, alphabet: alphabet)
62
- end
63
-
64
- private
65
-
66
- def self.simple_generate(size:)
67
- bytes = random_bytes(size)
68
-
69
- (0...size).reduce('') do |acc, i|
70
- acc << SAFE_ALPHABET[bytes[i] & 63]
71
- end
72
- end
73
-
74
- def self.complex_generate(size:, alphabet:)
75
- alphabet_size = alphabet.size
76
- mask = (2 << Math.log(alphabet_size - 1) / Math.log(2)) - 1
77
- step = (1.6 * mask * size / alphabet_size).ceil
78
-
79
- id = ''
80
-
81
- loop do
82
- bytes = random_bytes(size)
83
- (0...step).each do |idx|
84
- byte = bytes[idx] & mask
85
- character = byte && alphabet[byte]
86
- if character
87
- id << character
88
- return id if id.size == size
89
- end
90
- end
91
- end
92
- end
93
-
94
- def self.non_secure_generate(size:, alphabet:)
95
- alphabet_size = alphabet.size
96
-
97
- id = ''
98
-
99
- size.times do
100
- id << alphabet[(Random.rand * alphabet_size).floor]
101
- end
102
-
103
- id
104
- end
105
-
106
- def self.random_bytes(size)
107
- SecureRandom.random_bytes(size).bytes
108
- end
109
- end
110
- ```
@@ -1,109 +0,0 @@
1
- # Task List: OpaqueId Ruby Gem Implementation
2
-
3
- Based on PRD: `0001-prd-opaque-id-gem.md`
4
-
5
- ## Relevant Files
6
-
7
- - `lib/opaque_id.rb` - Main module with core ID generation functionality and error classes
8
- - `lib/opaque_id/version.rb` - Version constant (already exists)
9
- - `lib/opaque_id/model.rb` - ActiveRecord concern for model integration
10
- - `lib/generators/opaque_id/install_generator.rb` - Rails generator for migrations and model updates
11
- - `lib/generators/opaque_id/templates/migration.rb.tt` - Migration template for generator
12
- - `opaque_id.gemspec` - Gem specification and dependencies (updated for Rails 8.0+)
13
- - `Gemfile` - Development dependencies
14
- - `Rakefile` - Rake tasks for testing and linting
15
- - `.rubocop.yml` - RuboCop configuration for code quality
16
- - `test/test_helper.rb` - Test setup with Rails configuration and deprecation fixes
17
- - `test/test_opaque_id.rb` - Unit tests for main module
18
- - `test/opaque_id_test.rb` - Comprehensive tests for core functionality
19
- - `test/opaque_id/model_test.rb` - Unit tests for ActiveRecord concern
20
- - `test/opaque_id/generators/install_generator_test.rb` - Unit tests for generator
21
- - `README.md` - Documentation and usage examples
22
- - `CHANGELOG.md` - Version history and changes
23
-
24
- ### Notes
25
-
26
- - Unit tests should be placed in the `test/` directory following Minitest conventions
27
- - Use `ruby -Ilib:test test/test_opaque_id.rb` to run specific test files
28
- - Use `rake test` to run all tests (once Rakefile is configured)
29
- - The existing `test/test_helper.rb` already sets up Minitest and loads the gem
30
-
31
- ## Tasks
32
-
33
- - [x] 1.0 Implement Core ID Generation Module
34
-
35
- - [x] 1.1 Create error classes (Error, GenerationError, ConfigurationError)
36
- - [x] 1.2 Implement alphabet constants (STANDARD_ALPHABET, ALPHANUMERIC_ALPHABET)
37
- - [x] 1.3 Implement generate_fast method for 64-character alphabets using bitwise operations
38
- - [x] 1.4 Implement generate_unbiased method with rejection sampling algorithm
39
- - [x] 1.5 Implement main generate method with parameter validation
40
- - [x] 1.6 Add proper error handling for invalid size and empty alphabet
41
- - [x] 1.7 Add require statements for SecureRandom and version
42
-
43
- - [x] 2.0 Create ActiveRecord Model Integration
44
-
45
- - [x] 2.1 Create OpaqueId::Model concern with ActiveSupport::Concern
46
- - [x] 2.2 Implement before_create callback for automatic ID generation
47
- - [x] 2.3 Add find_by_opaque_id and find_by_opaque_id! class methods
48
- - [x] 2.4 Implement collision detection with configurable retry attempts
49
- - [x] 2.5 Add configuration options (column, length, alphabet, require_letter_start, purge_chars, max_retry)
50
- - [x] 2.6 Implement set_opaque_id private method with collision handling
51
- - [x] 2.7 Add generate_opaque_id private method using main module
52
- - [x] 2.8 Handle edge cases (already has ID, collision resolution failure)
53
-
54
- - [x] 3.0 Build Rails Generator for Easy Setup
55
-
56
- - [x] 3.1 Create lib/generators/opaque_id directory structure
57
- - [x] 3.2 Implement InstallGenerator class with Rails::Generators::Base
58
- - [x] 3.3 Add table_name argument and column_name option handling
59
- - [x] 3.4 Create migration template (migration.rb.tt) with add_column and add_index
60
- - [x] 3.5 Implement create_migration_file method with error handling
61
- - [x] 3.6 Add model file modification to include OpaqueId::Model
62
- - [x] 3.7 Handle edge cases (missing model file, already included, different class names)
63
- - [x] 3.8 Add proper console output and error messages
64
-
65
- - [x] 4.0 Update Gem Configuration and Dependencies
66
-
67
- - [x] 4.1 Update gemspec with proper summary and description
68
- - [x] 4.2 Add ActiveRecord and ActiveSupport dependencies (>= 8.0)
69
- - [x] 4.3 Add development dependencies (rake, sqlite3, rubocop, rails)
70
- - [x] 4.4 Update metadata (homepage, source_code_uri, changelog_uri)
71
- - [x] 4.5 Set required_ruby_version to >= 3.2
72
- - [x] 4.6 Configure file inclusion and exclusion patterns
73
- - [x] 4.7 Update Gemfile to match gemspec dependencies
74
- - [x] 4.8 Update Rakefile with test and rubocop tasks
75
-
76
- - [x] 5.0 Create Comprehensive Test Suite
77
-
78
- - [x] 5.1 Create test/opaque_id directory structure
79
- - [x] 5.2 Implement test_opaque_id.rb with core module tests
80
- - [x] 5.3 Add tests for generate method (default length, custom length, alphabet validation)
81
- - [x] 5.4 Add tests for error conditions (invalid size, empty alphabet)
82
- - [x] 5.5 Add statistical uniformity tests for character distribution
83
- - [x] 5.6 Add performance benchmark tests for different alphabet sizes
84
- - [x] 5.7 Create test/opaque_id/model_test.rb for ActiveRecord concern
85
- - [x] 5.8 Test model integration (automatic generation, find methods, configuration)
86
- - [x] 5.9 Test collision detection and retry logic
87
- - [x] 5.10 Create test/opaque_id/generators/install_generator_test.rb
88
- - [x] 5.11 Test generator behavior (migration creation, model modification, edge cases)
89
- - [x] 5.12 Add test database setup and cleanup
90
-
91
- - [x] 5.13 Configure RuboCop for code quality
92
-
93
- - [x] 5.13.1 Create .rubocop.yml configuration file
94
- - [x] 5.13.2 Set appropriate rules for gem development
95
- - [x] 5.13.3 Auto-correct all RuboCop offenses
96
- - [x] 5.13.4 Fix Rails 8.1 deprecation warning in test helper
97
-
98
- - [ ] 6.0 Write Documentation and Examples
99
- - [x] 6.1 Update README.md with comprehensive feature list
100
- - [x] 6.2 Add installation instructions and gem usage
101
- - [x] 6.3 Create basic usage examples with code snippets
102
- - [x] 6.4 Add custom configuration examples
103
- - [x] 6.5 Document standalone generation usage
104
- - [x] 6.6 Add configuration options table with defaults
105
- - [x] 6.7 Document alphabet options (ALPHANUMERIC_ALPHABET, STANDARD_ALPHABET)
106
- - [x] 6.8 Add algorithm explanation and performance benchmarks
107
- - [x] 6.9 Create security considerations and use case examples
108
- - [x] 6.10 Add contributing guidelines and license information
109
- - [x] 6.11 Update CHANGELOG.md with version history
@@ -1,177 +0,0 @@
1
- # Task List: Publishing & Release Automation Implementation (Release Please Approach)
2
-
3
- ## Summary
4
-
5
- Implement fully automated publishing and release system for OpaqueId gem using **Release Please** (Google's tool), **Bundler's release tasks**, and **RubyGems trusted publishing** with `rubygems/release-gem` action.
6
-
7
- ## Completed Tasks
8
-
9
- - [x] 0.1 Create comprehensive PRD for publishing and release automation
10
- - [x] 0.2 Research Ruby ecosystem equivalents to Changesets
11
- - [x] 0.3 Define technical requirements and dependencies
12
- - [x] 0.4 Update approach to use Release Please (Google's tool)
13
- - [x] 0.5 Implement complete automated publishing and release system
14
-
15
- ## Pending Tasks
16
-
17
- ### Phase 1: Core Release Please Setup (Priority: High)
18
-
19
- #### 1.0 Set Up Release Please Configuration
20
-
21
- - [x] 1.1 Create `release-please-config.json` configuration file
22
- - [x] 1.2 Configure Release Please for Ruby gem with `release-type: ruby`
23
- - [x] 1.3 Set up conventional commits parsing for version bumping
24
- - [x] 1.4 Configure changelog generation from conventional commits
25
- - [x] 1.5 Test Release Please configuration with sample commits
26
-
27
- #### 2.0 Create Release Please Workflow
28
-
29
- - [x] 2.1 Create `.github/workflows/release-please.yml` workflow
30
- - [x] 2.2 Configure workflow to run on push to main branch
31
- - [x] 2.3 Set up permissions for creating/updating release PRs
32
- - [x] 2.4 Configure workflow to use `googleapis/release-please-action@v4`
33
- - [x] 2.5 Test workflow with sample conventional commits
34
-
35
- #### 3.0 Set Up RubyGems Trusted Publishing
36
-
37
- - [ ] 3.1 Configure trusted publishing on RubyGems.org (UI step) - **MANUAL STEP REQUIRED**
38
- - [x] 3.2 Create `.github/workflows/publish.yml` workflow
39
- - [x] 3.3 Configure workflow to trigger on GitHub Release published
40
- - [x] 3.4 Set up OIDC permissions (`id-token: write`, `contents: write`)
41
- - [x] 3.5 Configure `rubygems/release-gem@v1` action for publishing
42
-
43
- ### Phase 2: Quality Gates & Security (Priority: High)
44
-
45
- #### 4.0 Implement Quality Gates
46
-
47
- - [x] 4.1 Add test execution to release-please workflow (via enhanced main.yml)
48
- - [x] 4.2 Add RuboCop execution to release-please workflow (via enhanced main.yml)
49
- - [x] 4.3 Add bundle audit for security scanning (via enhanced main.yml)
50
- - [x] 4.4 Configure workflow to fail on quality gate failures
51
- - [x] 4.5 Test quality gates with intentional failures
52
-
53
- #### 5.0 Configure Dependabot
54
-
55
- - [x] 5.1 Create `.github/dependabot.yml` configuration file
56
- - [x] 5.2 Configure weekly dependency updates (Monday 9 AM)
57
- - [x] 5.3 Set up security update prioritization
58
- - [x] 5.4 Configure update strategy and labels
59
- - [x] 5.5 Test dependabot with sample dependency updates
60
-
61
- ### Phase 3: Documentation & Testing (Priority: Medium)
62
-
63
- #### 6.0 Documentation and Testing
64
-
65
- - [x] 6.1 Document the complete Release Please workflow (in PRD and task files)
66
- - [x] 6.2 Create troubleshooting guide for release failures (in PRD)
67
- - [x] 6.3 Test complete release workflow end-to-end (local testing completed)
68
- - [x] 6.4 Create release process checklist (in PRD)
69
- - [x] 6.5 Update README with release automation information (comprehensive documentation)
70
-
71
- #### 7.0 Monitoring and Maintenance
72
-
73
- - [x] 7.1 Set up release monitoring and alerts (via GitHub Actions)
74
- - [ ] 7.2 Create release metrics dashboard (optional - not needed for MVP)
75
- - [x] 7.3 Implement release health checks (via CI workflows)
76
- - [x] 7.4 Set up automated dependency security scanning (via Dependabot and bundle-audit)
77
- - [x] 7.5 Create maintenance procedures for release system (documented in PRD)
78
-
79
- ## Technical Dependencies
80
-
81
- ### Required Tools
82
-
83
- - **Release Please**: Google's tool for PR-based versioning and changelog generation
84
- - **Bundler's release tasks**: Built-in rake tasks (already present from `bundle gem`)
85
- - **bundle-audit**: Security scanning
86
- - **rubygems/release-gem**: GitHub Action for RubyGems publishing
87
-
88
- ### Configuration Files
89
-
90
- - `release-please-config.json`: Release Please configuration
91
- - `.github/dependabot.yml`: Dependency update configuration
92
- - `.github/workflows/release-please.yml`: Release PR workflow
93
- - `.github/workflows/publish.yml`: Publishing workflow
94
-
95
- ### RubyGems Configuration
96
-
97
- - Trusted publishing setup on RubyGems.org
98
- - GitHub OIDC configuration
99
- - MFA requirement enforcement
100
-
101
- ## Workflow Overview
102
-
103
- ### Release Please Workflow (release-please.yml)
104
-
105
- ```yaml
106
- name: release-please
107
- on:
108
- push:
109
- branches: [main]
110
- permissions:
111
- contents: write
112
- pull-requests: write
113
- jobs:
114
- release:
115
- runs-on: ubuntu-latest
116
- steps:
117
- - uses: googleapis/release-please-action@v4
118
- with:
119
- release-type: ruby
120
- ```
121
-
122
- ### Publishing Workflow (publish.yml)
123
-
124
- ```yaml
125
- name: publish-gem
126
- on:
127
- release:
128
- types: [published]
129
- permissions:
130
- id-token: write
131
- contents: write
132
- jobs:
133
- push:
134
- name: Push gem to RubyGems.org
135
- runs-on: ubuntu-latest
136
- steps:
137
- - uses: actions/checkout@v4
138
- with:
139
- persist-credentials: false
140
- - uses: ruby/setup-ruby@v1
141
- with:
142
- ruby-version: ruby
143
- bundler-cache: true
144
- - uses: rubygems/release-gem@v1
145
- ```
146
-
147
- ## Success Criteria
148
-
149
- - [x] Release Please creates release PRs automatically from conventional commits
150
- - [x] Version file (`lib/opaque_id/version.rb`) is automatically updated
151
- - [x] Changelog is automatically generated from conventional commits
152
- - [x] Merging release PR creates GitHub Release and publishes to RubyGems.org
153
- - [x] All quality gates pass before release
154
- - [x] Dependencies are automatically updated weekly
155
- - [x] No manual intervention required for releases (except RubyGems trusted publishing setup)
156
- - [x] RubyGems trusted publishing works without API keys
157
-
158
- ## Relevant Files
159
-
160
- - `release-please-config.json` - Release Please configuration
161
- - `.github/workflows/release-please.yml` - Release PR workflow
162
- - `.github/workflows/publish.yml` - Publishing workflow
163
- - `.github/dependabot.yml` - Dependency update configuration
164
- - `lib/opaque_id/version.rb` - Version file for automatic updates
165
- - `CHANGELOG.md` - Auto-generated changelog
166
- - `opaque_id.gemspec` - Gem specification
167
- - `Rakefile` - Rake tasks for building and releasing
168
-
169
- ## Notes
170
-
171
- - This approach uses the widely-adopted Ruby ecosystem standard
172
- - Release Please provides the same ergonomics as Changesets
173
- - Uses RubyGems trusted publishing for enhanced security
174
- - Fully automated process with PR-based releases
175
- - Based on conventional commits specification
176
- - Compatible with existing gem structure and dependencies
177
- - No need for commitlint or pre-commit hooks (Release Please handles conventional commits)
@@ -1,84 +0,0 @@
1
- # Task List: OpaqueId Documentation Site
2
-
3
- ## Relevant Files
4
-
5
- - `docs/_config.yml` - Jekyll configuration file for the documentation site
6
- - `docs/Gemfile` - Ruby dependencies for Jekyll and Just the Docs theme
7
- - `docs/index.md` - Homepage of the documentation site
8
- - `docs/getting-started.md` - Quick start guide for developers
9
- - `docs/installation.md` - Detailed installation instructions
10
- - `docs/usage.md` - Usage examples and integration guides
11
- - `docs/configuration.md` - Configuration options and examples
12
- - `docs/alphabets.md` - Built-in alphabets and custom alphabet guide
13
- - `docs/algorithms.md` - Technical details about algorithms
14
- - `docs/performance.md` - Performance benchmarks and optimization
15
- - `docs/security.md` - Security considerations and best practices
16
- - `docs/use-cases.md` - Real-world examples and applications
17
- - `docs/development.md` - Contributing guidelines and development setup
18
- - `docs/api-reference.md` - Complete API documentation
19
- - `docs/assets/images/` - Directory for documentation images and assets
20
- - `.github/workflows/docs.yml` - GitHub Actions workflow for documentation deployment
21
- - `README.md` - Source content for documentation migration
22
-
23
- ### Notes
24
-
25
- - The documentation site will be completely separate from the main gem codebase
26
- - Jekyll uses Markdown files with YAML front matter for page configuration
27
- - GitHub Pages will automatically build and deploy the Jekyll site
28
- - All content will be manually migrated from the existing README.md
29
-
30
- ## Tasks
31
-
32
- - [x] 1.0 Set up Jekyll site structure and configuration
33
-
34
- - [x] 1.1 Create `/docs` directory structure
35
- - [x] 1.2 Initialize Jekyll site with `jekyll new docs --force`
36
- - [x] 1.3 Configure `_config.yml` for Just the Docs theme and GitHub Pages
37
- - [x] 1.4 Set up `Gemfile` with just-the-docs gem and GitHub Pages plugins
38
- - [x] 1.5 Configure site metadata (title, description, author, URL)
39
- - [x] 1.6 Set up proper permalinks and URL structure
40
- - [x] 1.7 Configure search functionality and navigation settings
41
-
42
- - [x] 2.0 Create GitHub Actions workflow for documentation deployment
43
-
44
- - [x] 2.1 Create `.github/workflows/docs.yml` workflow file
45
- - [x] 2.2 Configure workflow to trigger on pushes to main branch
46
- - [x] 2.3 Set up Jekyll build process with proper Ruby version
47
- - [x] 2.4 Configure GitHub Pages deployment with proper permissions
48
- - [x] 2.5 Add error handling and build status notifications
49
- - [x] 2.6 Test workflow with initial deployment
50
-
51
- - [x] 3.0 Migrate and organize content from README into documentation pages
52
-
53
- - [x] 3.1 Create homepage (`index.md`) with overview, badges, and introduction
54
- - [x] 3.2 Extract and create getting-started.md with quick start guide
55
- - [x] 3.3 Migrate installation content to installation.md with all methods
56
- - [x] 3.4 Create usage.md with standalone and ActiveRecord examples
57
- - [x] 3.5 Extract configuration options to configuration.md with examples
58
- - [x] 3.6 Create alphabets.md with built-in alphabets and custom guide
59
- - [x] 3.7 Migrate algorithm details to algorithms.md with technical explanations
60
- - [x] 3.8 Create performance.md with benchmarks and optimization tips
61
- - [x] 3.9 Extract security content to security.md with best practices
62
- - [x] 3.10 Create use-cases.md with real-world examples and applications
63
- - [x] 3.11 Migrate development content to development.md with setup instructions
64
- - [x] 3.12 Create api-reference.md with complete method documentation
65
-
66
- - [x] 4.0 Implement navigation structure and cross-references
67
-
68
- - [x] 4.1 Configure navigation in `_config.yml` with proper page ordering
69
- - [x] 4.2 Add proper YAML front matter to all pages with titles and descriptions
70
- - [x] 4.3 Create cross-references between related pages using markdown links
71
- - [x] 4.4 Add table of contents to longer pages using Just the Docs features
72
- - [x] 4.5 Implement proper heading hierarchy for consistent navigation
73
- - [x] 4.6 Add breadcrumb navigation where appropriate
74
- - [x] 4.7 Test navigation flow and ensure all links work correctly
75
-
76
- - [x] 5.0 Configure Just the Docs theme and optimize for GitHub Pages
77
- - [x] 5.1 Customize theme colors and branding to match OpaqueId
78
- - [x] 5.2 Configure code syntax highlighting for Ruby examples
79
- - [x] 5.3 Set up responsive design and mobile optimization
80
- - [x] 5.4 Add SEO meta tags and Open Graph properties
81
- - [x] 5.5 Configure sitemap and RSS feed generation
82
- - [x] 5.6 Optimize page loading speed and performance
83
- - [x] 5.7 Test site functionality across different browsers and devices
84
- - [x] 5.8 Validate HTML and accessibility compliance