Module: DynamicActiveModel::DangerousAttributesPatch
- Defined in:
- lib/dynamic-active-model/dangerous_attributes_patch.rb
Overview
The DangerousAttributesPatch module is a safety feature that prevents conflicts between database column names and Ruby reserved words or ActiveRecord methods. It automatically detects and ignores columns that could cause conflicts, particularly focusing on boolean columns that might conflict with Ruby’s question mark methods.
Class Method Summary collapse
-
.included(base) ⇒ Object
Extends the including class with dangerous attribute protection This method: 1.
Class Method Details
.included(base) ⇒ Object
Extends the including class with dangerous attribute protection This method:
-
Checks if the class has any attributes
-
Identifies columns that could cause conflicts
-
Adds those columns to the ignored_columns list
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dynamic-active-model/dangerous_attributes_patch.rb', line 27 def self.included(base) return unless base.attribute_names columns_to_ignore = base.columns.select do |column| if column.type == :boolean base.dangerous_attribute_method?(column.name) || base.dangerous_attribute_method?("#{column.name}?") else base.dangerous_attribute_method?(column.name) end end base.ignored_columns = columns_to_ignore.map(&:name) end |