Module: Exclude::ClassMethods

Defined in:
lib/exclude.rb

Instance Method Summary collapse

Instance Method Details

#exclude(*columns_to_subtract) ⇒ Object

Returns a scope selecting all columns on the table except those specified in the passed array (or string/symbol for one column).



9
10
11
12
13
14
15
16
# File 'lib/exclude.rb', line 9

def exclude(*columns_to_subtract)
  columns_to_subtract = [*columns_to_subtract]
  selected_columns = self.column_names - columns_to_subtract
  
  select selected_columns.map { |c| "#{self.table_name}.#{c}" }.join(', ')
rescue
  puts "Columns not available for `exclude`"
end