Sha256: a218982ffaa99b5ef1db159addcf9c2a94946503169128d74ef04d11245311c2
Contents?: true
Size: 819 Bytes
Versions: 1
Compression:
Stored size: 819 Bytes
Contents
module Hatio module Stripper def self.included(base) super base.extend(ClassMethods) base.class_eval do include InstanceMethods class_attribute :strip_fields end end module ClassMethods def strip_cols(cols) class_eval do self.strip_fields = cols before_validation :strip_vals end end end module InstanceMethods private def strip_vals assign_attrs = {} self.strip_fields.each do |col| val = self.attributes[col.to_s] val = val.strip if(val && val.respond_to?(:strip)) assign_attrs[col.to_s] = val end self.assign_attributes(assign_attrs) unless(assign_attrs.empty?) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hatio-core-0.0.6 | lib/hatio-core/active_record/stripper.rb |