2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-04 18:41:04 -04:00
|
|
|
# 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-08-27 08:35:31 -04:00
|
|
|
class_methods do
|
2017-04-04 18:41:04 -04:00
|
|
|
def columns
|
|
|
|
super.reject { |column| ignored_columns.include?(column.name) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def ignored_columns
|
|
|
|
@ignored_columns ||= Set.new
|
|
|
|
end
|
|
|
|
|
2017-11-06 10:20:20 -05:00
|
|
|
def ignore_column(*names)
|
|
|
|
ignored_columns.merge(names.map(&:to_s))
|
2017-04-04 18:41:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|