LegacyColumn
A gem that will print a message if a developer is trying to use a column that is from a legacy system but has to stay there.
Installation
Add this line to your application's Gemfile:
gem 'legacy_column'And then execute:
bundle installCompatibility
This gem supports:
- Ruby 2.7+
- Rails 5.2+, 6.0+, 6.1+, 7.0+, 7.1+, 7.2+, 8.0+
Usage
Basic Usage
Just list the column names:
legacy_column :old_email, :old_phone_numberA custom message can be added:
legacy_column :old_email, :old_phone_number, message: 'Do not touch this!!!'Read Access Detection
By default, the gem only detects write operations (when columns are modified). To also detect read access, use the detect_reads option:
legacy_column :old_email, :old_phone_number, detect_reads: trueThis will warn whenever the legacy columns are accessed:
legacy_column :old_status, message: 'This field is deprecated!', detect_reads: true
user.old_status  # Will log a warning about read access
user.old_status = 'active'  # Will log a warning about write accessCombined Usage
You can combine read detection with custom messages:
legacy_column :old_price, :old_name, 
              message: 'These fields will be removed in v2.0!', 
              detect_reads: trueOutput Examples
Write Detection (Default)
USE of legacy column detected.
  User => old_email
  Do not touch this!!!
Read Detection (When enabled)
READ of legacy column detected.
  User => old_email
  Do not touch this!!!
Logging
The gem will:
- Log warnings to Rails.loggerwhen Rails is available
- Fall back to putsfor non-Rails environments or when Rails.logger is not available
Options
| Option | Default | Description | 
|---|---|---|
| message | "This column is set as legacy and should not be used anymore." | Custom warning message | 
| detect_reads | false | Enable read access detection | 
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.