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:
|
|
|
|
#
|
2019-05-30 16:15:17 +05:30
|
|
|
# class User < ActiveRecord::Base
|
2017-08-17 22:00:37 +05:30
|
|
|
# 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
|