Module: AutoStripAttributes
- Defined in:
- lib/auto_strip_attributes.rb,
lib/auto_strip_attributes/version.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
"2.3.0"
Instance Method Summary collapse
Instance Method Details
#auto_strip_attributes(*attributes) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/auto_strip_attributes.rb', line 4 def auto_strip_attributes(*attributes) = AutoStripAttributes::Config.filters_enabled if attributes.last.is_a?(Hash) = .merge(attributes.pop) end # option `:virtual` is needed because we want to guarantee that # getter/setter methods for an attribute will _not_ be invoked by default virtual = .delete(:virtual) attributes.each do |attribute| before_validation do |record| #debugger if virtual value = record.public_send(attribute) else value = record[attribute] end AutoStripAttributes::Config.filters_order.each do |filter_name| next unless [filter_name] value = AutoStripAttributes::Config.filters[filter_name].call value if virtual record.public_send("#{attribute}=", value) else record[attribute] = value end end end end end |