mm-sanitize 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mm-sanitize.rb +11 -1
  3. metadata +3 -3
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ spec = Gem::Specification.new do |s|
21
21
 
22
22
  # Change these as appropriate
23
23
  s.name = "mm-sanitize"
24
- s.version = "0.1.0"
24
+ s.version = "0.1.1"
25
25
  s.summary = "Tiny plugin for MongoMapper to sanitize strings before validation."
26
26
  s.author = "Richard Livsey"
27
27
  s.email = "youremail@example.com"
data/lib/mm-sanitize.rb CHANGED
@@ -31,7 +31,17 @@ module MongoMapper
31
31
  module InstanceMethods
32
32
  def sanitize_attributes
33
33
  self.class.sanitize_keys.each do |key, config|
34
- self[key] = ::Sanitize.clean(self[key], config || {})
34
+ config ||= {}
35
+
36
+ if val = self[key]
37
+ if val.is_a?(Array) || val.is_a?(Set)
38
+ self[key] = val.collect{|v| ::Sanitize.clean(v, config) }
39
+ elsif val.is_a?(Hash)
40
+ self[key] = val.each{|k, v| val[k] = ::Sanitize.clean(v, config) if v.is_a?(String) }
41
+ elsif val.is_a?(String)
42
+ self[key] = ::Sanitize.clean(val, config)
43
+ end
44
+ end
35
45
  end
36
46
  end
37
47
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-sanitize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Livsey