Module: DataMapper::Sanitizer::InstanceMethods

Defined in:
lib/dm-sanitizer.rb

Instance Method Summary collapse

Instance Method Details

#sanitize!Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dm-sanitizer.rb', line 75

def sanitize!
  options = self.class.sanitization_options
  return false if options[:disabled]
  
  self.class.properties.each do |property|
    property_name = property.name.to_sym
    
    next unless options[:property_types].include?(property.class)
    next if !new? && !options[:with_dirty] && !attribute_dirty?(property.name.to_sym)
    next if options[:exclude] && options[:exclude].include?(property_name)
    
    property_mode = options[:modes] ? options[:modes][property_name] || options[:default_mode] : options[:default_mode]
    
    sanitize_property!(property_name, property_mode)
  end
  return true
end

#sanitize_property!(name, mode) ⇒ Object



93
94
95
96
97
98
# File 'lib/dm-sanitizer.rb', line 93

def sanitize_property!(name, mode)
  value = self.send( name )
  return if value.nil? || value.empty?
  sanitized_value = Sanitize.clean(value, self.class.sanitization_options[:mode_definitions][mode])
  self.send( name.to_s+'=', sanitized_value)
end