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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 535f7f0cf97ddb8664e239bfb344ee344763f4f9992ae47a30bbdc23b7eb4c6a
4
- data.tar.gz: f6b8b87729c7c566cb14b31f6579107f01880ea4e713649a6e8b2694ae4aca9a
3
+ metadata.gz: 85226caa9d5bbc68eedc7aecda5105a079c13733853522736aa1fb04f6d99477
4
+ data.tar.gz: 5bfe2a1075d98348dad53b5b569d86e21c16938908f91ef08ea97015076df351
5
5
  SHA512:
6
- metadata.gz: 044c101dcebc4c309d96a7fbe9a21d4b00f95f3e72b9685a843e08e2ac6475aead151f78b585e51a7a3ae705971543f46c71af7fcc8f2711579fc5a8a617407f
7
- data.tar.gz: 4ac279aef93d9311b5450261df822179fe743f0c3c2a4d9293f25cf95c3ca117d06d6313c77a7271cec0e2510fe999b8fc99ff5c0d4d61402fbf7170b3261a87
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:
@@ -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) }
@@ -0,0 +1,5 @@
1
+ module PublicCode
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks { load File.expand_path("../tasks/public_code.rake", __dir__) }
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module PublicCode
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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