module ColumnHider::ActiveRecordAttributes
Overrides the Rails ActiveRecord Attributes “columns” method. This allows the logical removal of a column prior to its physical removal. To use, add two lines to your model: ` extend ColumnHider::ActiveRecordAttributes` ` column_hider_columns
:column_one, :column_two, …` If you want to deprecate the columns, call: ` column_hider_deprecate_columns
:column_one, :column_two, …`
This will also hide the columns
Public Instance Methods
column_hider_columns(*cols)
click to toggle source
# File lib/column_hider.rb, line 15 def column_hider_columns(*cols) @column_hider_columns = {} cols.each do |col| @column_hider_columns[col] = true end end
column_hider_deprecate_columns(*cols)
click to toggle source
# File lib/column_hider.rb, line 27 def column_hider_deprecate_columns(*cols) cols.each do |c| define_method("#{c}".to_sym) do raise NoMethodError.new("column '#{c}' deprecated", c.to_sym) end define_method("#{c}=".to_sym) do |arg| raise NoMethodError.new("column '#{c}' deprecated", c.to_sym) end end column_hider_columns(*cols) end
columns()
click to toggle source
Calls superclass method
# File lib/column_hider.rb, line 22 def columns @column_hider_columns ||= {} # just in case the model has "extend ColumnHider::ActiveRecordAttributes", but doesn't call column_hider_columns super.reject { |col| @column_hider_columns.has_key?(col.name.to_sym) } end