opaque_id 1.1.0 → 1.2.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 +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +22 -0
- data/lib/generators/opaque_id/install_generator.rb +38 -23
- data/lib/opaque_id/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd5ba8719a66fe85b84a3e1a35a8bb9633bbcbdea2662e9c1acd15760555b8f3
|
4
|
+
data.tar.gz: cd058abe2c91fa577ca4ccb83b5f827119115693f9fd3fea9bb77d8e4397e4c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a691ff3e5ddfafaf0a31b65f57661692f58f2fe60dbbecc916d615ba1c47f6743a52e5e36e08c02c844a226531e19a5c1ae5876e9e7dc580ccab7f888d4f3fe
|
7
|
+
data.tar.gz: 4c158a2dac2569612ef7d2572f2cd69e025777407e7b780f6abab0b201089585c12cfe9b4dadf636f6696576acd485f8c14b65c7d072488fdae57f810eac591d
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,28 @@ All notable changes to the OpaqueId gem will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [1.2.0](https://github.com/nyaggah/opaque_id/compare/opaque_id/v1.1.0...opaque_id/v1.2.0) (2025-10-02)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* improve generator API and add custom column configuration ([5c1a570](https://github.com/nyaggah/opaque_id/commit/5c1a5703dee269f6985d26096942c086787296f3))
|
14
|
+
|
15
|
+
|
16
|
+
### Styles
|
17
|
+
|
18
|
+
* improve code formatting in generator ([ce52021](https://github.com/nyaggah/opaque_id/commit/ce52021cd60e3594dc1ee34e5b96d48568008b5a))
|
19
|
+
|
20
|
+
|
21
|
+
### Code Refactoring
|
22
|
+
|
23
|
+
* improve generator code quality and resolve RuboCop issues ([b658bbc](https://github.com/nyaggah/opaque_id/commit/b658bbcb29f6c0134f2bf256b24c5b3c2bccb265))
|
24
|
+
|
25
|
+
|
26
|
+
### Tests
|
27
|
+
|
28
|
+
* add test for lowercase model names ([8ef4675](https://github.com/nyaggah/opaque_id/commit/8ef4675a0698d2cda054084360c9e80d956ddb14))
|
29
|
+
|
8
30
|
## [1.1.0](https://github.com/nyaggah/opaque_id/compare/opaque_id-v1.0.2...opaque_id/v1.1.0) (2025-10-02)
|
9
31
|
|
10
32
|
|
@@ -10,47 +10,62 @@ module OpaqueId
|
|
10
10
|
|
11
11
|
source_root File.expand_path('templates', __dir__)
|
12
12
|
|
13
|
-
argument :
|
13
|
+
argument :model_name, type: :string, default: nil, banner: 'ModelName'
|
14
14
|
|
15
15
|
class_option :column_name, type: :string, default: 'opaque_id',
|
16
16
|
desc: 'Name of the column to add'
|
17
17
|
|
18
18
|
def create_migration_file
|
19
|
-
if
|
19
|
+
if model_name.present?
|
20
|
+
table_name = model_name.tableize
|
20
21
|
migration_template 'migration.rb.tt',
|
21
22
|
"db/migrate/add_opaque_id_to_#{table_name}.rb"
|
22
23
|
|
23
24
|
add_include_to_model
|
24
25
|
else
|
25
|
-
say 'Usage: rails generate opaque_id:install
|
26
|
-
say 'Example: rails generate opaque_id:install
|
26
|
+
say 'Usage: rails generate opaque_id:install ModelName', :red
|
27
|
+
say 'Example: rails generate opaque_id:install User', :green
|
28
|
+
say 'Example: rails generate opaque_id:install Post --column-name=public_id', :green
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def add_include_to_model
|
33
|
-
model_path = "app/models/#{
|
34
|
-
|
35
|
-
|
36
|
-
# Read existing model file
|
37
|
-
content = File.read(model_path)
|
38
|
-
|
39
|
-
# Check if already included
|
40
|
-
if content.include?('include OpaqueId::Model')
|
41
|
-
say "OpaqueId::Model already included in #{model_path}", :yellow
|
42
|
-
else
|
43
|
-
# Add include statement
|
44
|
-
content.gsub!(/class #{table_name.classify} < ApplicationRecord/,
|
45
|
-
"class #{table_name.classify} < ApplicationRecord\n include OpaqueId::Model")
|
46
|
-
|
47
|
-
# Write back to file
|
48
|
-
File.write(model_path, content)
|
49
|
-
say "Updated #{model_path}", :green
|
50
|
-
end
|
51
|
-
else
|
35
|
+
model_path = "app/models/#{model_name.underscore}.rb"
|
36
|
+
|
37
|
+
unless File.exist?(model_path)
|
52
38
|
say "Model file #{model_path} not found. Please add 'include OpaqueId::Model' manually.", :yellow
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
content = File.read(model_path)
|
43
|
+
if content.include?('include OpaqueId::Model')
|
44
|
+
say "OpaqueId::Model already included in #{model_path}", :yellow
|
45
|
+
return
|
53
46
|
end
|
47
|
+
|
48
|
+
update_model_file(model_path, content)
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_model_file(model_path, content)
|
52
|
+
include_statement = build_include_statement
|
53
|
+
updated_content = content.gsub(/class #{model_name} < ApplicationRecord/,
|
54
|
+
"class #{model_name} < ApplicationRecord\n#{include_statement}")
|
55
|
+
|
56
|
+
File.write(model_path, updated_content)
|
57
|
+
say "Updated #{model_path}", :green
|
58
|
+
say " Set opaque_id_column to :#{options[:column_name]}", :green if custom_column?
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_include_statement
|
62
|
+
statement = ' include OpaqueId::Model'
|
63
|
+
statement += "\n self.opaque_id_column = :#{options[:column_name]}" if custom_column?
|
64
|
+
statement
|
65
|
+
end
|
66
|
+
|
67
|
+
def custom_column?
|
68
|
+
options[:column_name] != 'opaque_id'
|
54
69
|
end
|
55
70
|
end
|
56
71
|
end
|
data/lib/opaque_id/version.rb
CHANGED