Class: CleanRoom::Filter

Inherits:
Object
  • Object
show all
Extended by:
SanitizeUrl
Defined in:
lib/clean_room/filter.rb

Class Method Summary collapse

Class Method Details

.clean(dirty_value, rules = {}) ⇒ Object



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/clean_room/filter.rb', line 10

def clean(dirty_value, rules = {})
  nested_rules = rules[:nested_rules] || {}

  case dirty_value
  when Array
    dirty_value.map{ |dv| clean(dv, rules) }
  when Hash
    Hash[dirty_value.map {|k,dv| [clean(k, allow: (k.is_a?(Symbol) ? :symbol : :string)),clean(dv, nested_rules[k] ? nested_rules[k] : rules)]}]
  when Fixnum
    dirty_value
  when Symbol
    filter(dirty_value, rule: :symbol)
  when FalseClass
    false
  when NilClass
    nil
  else
    if dirty_value.class.to_s == "ActionDispatch::Http::UploadedFile"        
      dirty_value
    else
      filter(dirty_value, rules)
    end
  end
end