public_code 0.2.0 → 0.3.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/CHANGELOG.md +7 -0
- data/README.md +13 -0
- data/lib/public_code/model.rb +1 -0
- data/lib/public_code/railtie.rb +5 -0
- data/lib/public_code/version.rb +1 -1
- data/lib/public_code.rb +4 -0
- data/lib/tasks/public_code.rake +11 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85226caa9d5bbc68eedc7aecda5105a079c13733853522736aa1fb04f6d99477
|
|
4
|
+
data.tar.gz: 5bfe2a1075d98348dad53b5b569d86e21c16938908f91ef08ea97015076df351
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b25139d8cc38a6ef010df8bd0167022f39e35469d89a80c026386603224d23128d21079c193981c074bd4ff0bedf4212c826668568f36792b81479be1519b25
|
|
7
|
+
data.tar.gz: 5909c90e24ef0e6dc33956b1454b20b7d0f37c47c327f3923649774da7a8a26a00712195359041436d9e7c06fbbcee5256d26cd1516c9308fa51e05cd3b96a57
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2026-10-12
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `bin/rails public_code:status` lists every model that declares a code and whether it is addressed by code or by id.
|
|
10
|
+
- With `STRICT=1` the status task fails naming each model still addressed by id.
|
|
11
|
+
|
|
5
12
|
## [0.2.0] - 2026-10-12
|
|
6
13
|
|
|
7
14
|
### Added
|
data/README.md
CHANGED
|
@@ -89,6 +89,19 @@ column with the gem and name it in the gem's changelog.
|
|
|
89
89
|
An app switches a gem's records to codes by copying and running that migration,
|
|
90
90
|
then restarting so the new column is seen.
|
|
91
91
|
|
|
92
|
+
## Seeing which models still use ids
|
|
93
|
+
|
|
94
|
+
In a Rails app:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
bin/rails public_code:status
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
It lists every model that declares a code and says whether it is addressed by
|
|
101
|
+
code or by id. With `STRICT=1` it fails when any model is still addressed by
|
|
102
|
+
id, and names each one, so a deploy or CI step can require every migration to
|
|
103
|
+
have run.
|
|
104
|
+
|
|
92
105
|
## Checking pages for numbered links
|
|
93
106
|
|
|
94
107
|
In an integration test:
|
data/lib/public_code/model.rb
CHANGED
|
@@ -4,6 +4,7 @@ module PublicCode
|
|
|
4
4
|
|
|
5
5
|
class_methods do
|
|
6
6
|
def has_public_code(column = :public_code)
|
|
7
|
+
PublicCode.models << self
|
|
7
8
|
define_singleton_method(:public_code_column?) { table_exists? && column_names.include?(column.to_s) }
|
|
8
9
|
define_method(:give_public_code) { self[column] ||= PublicCode.generate if self.class.public_code_column? }
|
|
9
10
|
define_method(:"regenerate_#{column}") { update!(column => PublicCode.generate) }
|
data/lib/public_code/version.rb
CHANGED
data/lib/public_code.rb
CHANGED
|
@@ -8,6 +8,10 @@ module PublicCode
|
|
|
8
8
|
LENGTH = 24
|
|
9
9
|
|
|
10
10
|
def self.generate = ActiveRecord::Base.generate_unique_secure_token(length: LENGTH)
|
|
11
|
+
|
|
12
|
+
def self.models = @models ||= []
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
ActiveSupport.on_load(:active_record) { include PublicCode::Model }
|
|
16
|
+
|
|
17
|
+
require "public_code/railtie" if defined?(Rails::Railtie)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
namespace :public_code do
|
|
2
|
+
desc "List each model that declares a code and whether it is addressed by code or by id, failing on any by id when STRICT=1"
|
|
3
|
+
task status: :environment do
|
|
4
|
+
Rails.application.eager_load! if defined?(Rails.application) && Rails.application
|
|
5
|
+
models = PublicCode.models.sort_by(&:name)
|
|
6
|
+
models.each { |model| puts "#{model.name} addressed by #{model.public_code_column? ? "code" : "id"}" }
|
|
7
|
+
|
|
8
|
+
by_id = models.reject(&:public_code_column?)
|
|
9
|
+
abort "Still addressed by id: #{by_id.map(&:name).join(", ")}" if ENV["STRICT"] == "1" && by_id.any?
|
|
10
|
+
end
|
|
11
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: public_code
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tyler Schneider
|
|
@@ -50,8 +50,10 @@ files:
|
|
|
50
50
|
- README.md
|
|
51
51
|
- lib/public_code.rb
|
|
52
52
|
- lib/public_code/model.rb
|
|
53
|
+
- lib/public_code/railtie.rb
|
|
53
54
|
- lib/public_code/test_help.rb
|
|
54
55
|
- lib/public_code/version.rb
|
|
56
|
+
- lib/tasks/public_code.rake
|
|
55
57
|
homepage: https://github.com/DYB-Development/public_code
|
|
56
58
|
licenses:
|
|
57
59
|
- MIT
|