smart_ignored_columns 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c67e99e40687eaadf166a0e4c4815f1dedd1c463f9cd62378c6fe260e5510906
4
+ data.tar.gz: 0d8bca5ce9a22239dd199d174972cd4654b0e3c3100280bdc69c618b596fb71c
5
+ SHA512:
6
+ metadata.gz: e7a29f49845c5b522708f6d084899fd1795be5ba65c26af296672ab2cc0f54fe7ce5862f553432fadd28b6de1bcf0277cb2c85e6086c41af819bd3efd53208c8
7
+ data.tar.gz: 50153003d3b09fd17f97aee84f76615ed17e8516700476447898adb745b859180edd320dc2a28502bd1b8152e006500961d6e15414e9884a722fc7caf6900bd5
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## master (unreleased)
2
+
3
+ ## 0.1.0 (2025-08-28)
4
+
5
+ - First release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 fatkodima
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # SmartIgnoredColumns
2
+
3
+ [<img src="tweet.png" alt="Motivational tweet" width="500px"/>](https://x.com/ciaran_lee/status/1953084875193385200)
4
+
5
+ Now you won't forget to delete those ignored columns.
6
+
7
+ ## Requirements
8
+
9
+ - ruby 3.2+
10
+ - activerecord 7.2+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem "smart_ignored_columns", group: [:development, :test]
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ 1. Specify deadlines when ignoring columns:
23
+
24
+ ```ruby
25
+ class User < ApplicationRecord
26
+ self.ignored_columns += [
27
+ { name: "first_name", remove_after: "2025-08-24" } # date can be a String or a Date
28
+ ]
29
+ end
30
+ ```
31
+
32
+ 2. Run a check on CI to warn when it is time to remove ignored columns:
33
+
34
+ ```sh
35
+ bundle exec rake smart_ignored_columns:obsolete
36
+ ```
37
+
38
+ If there are any obsolete ignored columns, the check will print them and exit with an error status code.
39
+
40
+ If you want to print all ignored columns with their deadlines, run:
41
+
42
+ ```sh
43
+ bundle exec rake smart_ignored_columns:list
44
+ ```
45
+
46
+ ## Development
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fatkodima/smart_ignored_columns.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartIgnoredColumns
4
+ # Includes extension of the `ignored_columns=` method.
5
+ #
6
+ module Extension
7
+ # Extension of the default `ignored_columns=` method with an ability to specify deadlines.
8
+ #
9
+ # @example
10
+ # class User < ApplicationRecord
11
+ # self.ignored_columns += [
12
+ # { name: "first_name", remove_after: "2025-08-24" }, # date can be a String
13
+ # { name: "bio", remove_after: Date.parse("2025-08-24") }, # or a Date object
14
+ # ]
15
+ # end
16
+ #
17
+ def ignored_columns=(columns)
18
+ columns = columns.flatten
19
+
20
+ all_columns_valid = columns.all? do |column|
21
+ column.is_a?(Hash) && column.key?(:name) && column.key?(:remove_after)
22
+ end
23
+
24
+ unless all_columns_valid
25
+ raise ArgumentError, "columns should be an array of hashes, each containing :name and :remove_after options"
26
+ end
27
+
28
+ super(columns.pluck(:name))
29
+
30
+ self.smart_ignored_columns += columns.map do |column|
31
+ IgnoredColumn.new(column[:name], column[:remove_after])
32
+ end
33
+ end
34
+
35
+ # @private
36
+ def smart_ignored_columns
37
+ @smart_ignored_columns || superclass.try(:smart_ignored_columns) || []
38
+ end
39
+
40
+ # @private
41
+ def smart_ignored_columns=(columns)
42
+ @smart_ignored_columns = columns
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartIgnoredColumns
4
+ # @private
5
+ class IgnoredColumn
6
+ def self.all
7
+ list = []
8
+
9
+ ActiveRecord::Base.descendants.each do |klass|
10
+ next if klass.abstract_class?
11
+
12
+ if klass.smart_ignored_columns.any?
13
+ list << [klass, klass.smart_ignored_columns]
14
+ end
15
+ end
16
+
17
+ list
18
+ end
19
+
20
+ def self.obsolete
21
+ list = []
22
+
23
+ all.each do |klass, columns|
24
+ obsolete_columns = columns.select(&:obsolete?)
25
+ if obsolete_columns.any?
26
+ list << [klass, obsolete_columns]
27
+ end
28
+ end
29
+
30
+ list
31
+ end
32
+
33
+ attr_reader :name, :remove_after
34
+
35
+ def initialize(name, remove_after)
36
+ @name = name.to_s
37
+
38
+ @remove_after =
39
+ if remove_after.is_a?(String)
40
+ Date.parse(remove_after)
41
+ else
42
+ remove_after
43
+ end
44
+ end
45
+
46
+ def obsolete?
47
+ @remove_after < Date.today
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartIgnoredColumns
4
+ # @private
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "tasks/smart_ignored_columns_tasks.rake"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartIgnoredColumns
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+
5
+ require_relative "smart_ignored_columns/ignored_column"
6
+ require_relative "smart_ignored_columns/extension"
7
+ require_relative "smart_ignored_columns/version"
8
+
9
+ ActiveSupport.on_load(:active_record) do
10
+ singleton_class.prepend(SmartIgnoredColumns::Extension)
11
+ end
12
+
13
+ require "smart_ignored_columns/railtie" if defined?(Rails)
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :smart_ignored_columns do
4
+ desc "Show a list of obsolete `ignored_columns`"
5
+ task obsolete: :environment do
6
+ Rails.application.eager_load!
7
+
8
+ list = SmartIgnoredColumns::IgnoredColumn.obsolete
9
+
10
+ if list.any?
11
+ puts "The following `ignored_columns` definitions are obsolete and can be removed:\n\n"
12
+
13
+ list.each do |klass, ignored_columns|
14
+ puts klass.name
15
+ ignored_columns.each do |column|
16
+ puts " - #{column.name} (remove after #{column.remove_after})"
17
+ end
18
+ end
19
+
20
+ exit(1)
21
+ else
22
+ puts "No obsolete `ignored_columns` definitions found."
23
+ end
24
+ end
25
+
26
+ desc "Show a list of `ignored_columns`"
27
+ task list: :environment do
28
+ Rails.application.eager_load!
29
+
30
+ list = SmartIgnoredColumns::IgnoredColumn.all
31
+
32
+ if list.any?
33
+ list.each do |klass, ignored_columns|
34
+ puts klass.name
35
+ ignored_columns.each do |column|
36
+ puts " - #{column.name} (remove after #{column.remove_after})"
37
+ end
38
+ end
39
+ else
40
+ puts "No `ignored_columns` definitions found."
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_ignored_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fatkodima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.2'
27
+ description:
28
+ email:
29
+ - fatkodima123@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - LICENSE.txt
36
+ - README.md
37
+ - lib/smart_ignored_columns.rb
38
+ - lib/smart_ignored_columns/extension.rb
39
+ - lib/smart_ignored_columns/ignored_column.rb
40
+ - lib/smart_ignored_columns/railtie.rb
41
+ - lib/smart_ignored_columns/version.rb
42
+ - lib/tasks/smart_ignored_columns_tasks.rake
43
+ homepage: https://github.com/fatkodima/smart_ignored_columns
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/fatkodima/smart_ignored_columns
48
+ source_code_uri: https://github.com/fatkodima/smart_ignored_columns
49
+ changelog_uri: https://github.com/fatkodima/smart_ignored_columns/blob/master/CHANGELOG.md
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.2.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.4.19
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Add deadlines to Active Record `ignored_columns`
69
+ test_files: []