Module: Ignorable::ClassMethods
- Defined in:
- lib/ignorable.rb
Instance Method Summary collapse
-
#columns ⇒ Object
:nodoc:.
-
#ignore_columns(*columns) ⇒ Object
(also: #ignore_column)
Prevent Rails from loading a table column.
-
#ignored_column?(column) ⇒ Boolean
Has a column been ignored? Accepts both ActiveRecord::ConnectionAdapter::Column objects, and actual column names (‘title’).
- #reset_ignored_columns ⇒ Object
Instance Method Details
#columns ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/ignorable.rb', line 12 def columns # :nodoc: @columns ||= super.reject{|col| ignored_column?(col)} end |
#ignore_columns(*columns) ⇒ Object Also known as: ignore_column
Prevent Rails from loading a table column. Useful for legacy database schemas with problematic column names, like ‘class’ or ‘attributes’.
class Topic < ActiveRecord::Base
ignore_columns :attributes, :class
end
Topic.new.respond_to?(:attributes) => false
25 26 27 28 29 30 31 |
# File 'lib/ignorable.rb', line 25 def ignore_columns(*columns) self.ignored_columns ||= [] self.ignored_columns += columns.map(&:to_s) reset_column_information descendants.each(&:reset_column_information) self.ignored_columns.tap(&:uniq!) end |
#ignored_column?(column) ⇒ Boolean
Has a column been ignored? Accepts both ActiveRecord::ConnectionAdapter::Column objects, and actual column names (‘title’)
37 38 39 40 41 |
# File 'lib/ignorable.rb', line 37 def ignored_column?(column) self.ignored_columns.present? && self.ignored_columns.include?( column.respond_to?(:name) ? column.name : column.to_s ) end |
#reset_ignored_columns ⇒ Object
43 44 45 46 |
# File 'lib/ignorable.rb', line 43 def reset_ignored_columns self.ignored_columns = [] reset_column_information end |