debian-mirror-gitlab/app/models/concerns/ignorable_column.rb

31 lines
588 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
# Module that can be included into a model to make it easier to ignore database
# columns.
#
# Example:
#
# class User < ActiveRecord::Base
# include IgnorableColumn
#
# ignore_column :updated_at
# end
#
module IgnorableColumn
extend ActiveSupport::Concern
2018-11-20 20:47:30 +05:30
class_methods do
2017-08-17 22:00:37 +05:30
def columns
super.reject { |column| ignored_columns.include?(column.name) }
end
def ignored_columns
@ignored_columns ||= Set.new
end
2018-03-17 18:26:18 +05:30
def ignore_column(*names)
ignored_columns.merge(names.map(&:to_s))
2017-08-17 22:00:37 +05:30
end
end
end