Class: CGIMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/serve_webdav/raw_data_patch.rb,
lib/serve_webdav/raw_data_patch.rb

Class Method Summary collapse

Class Method Details

.parse_request_parameters(params) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/serve_webdav/raw_data_patch.rb', line 60

def CGIMethods.parse_request_parameters(params)
  parsed_params = {}

  for key, value in params
    value = [value] if key =~ /.*\[\]$/
    next if key.nil?
    if !key.nil? && !key.include?('[')
      # much faster to test for the most common case first (GET)
      # and avoid the call to build_deep_hash
      parsed_params[key] = get_typed_value(value[0])
    else
      build_deep_hash(get_typed_value(value[0]), parsed_params, get_levels(key))
    end
  end

  parsed_params
end

.typecast_xml_value(value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/serve_webdav/raw_data_patch.rb', line 26

def self.typecast_xml_value(value)
  case value
  when Hash
    if value.has_key?("__content__")
      content = translate_xml_entities(value["__content__"])
      case value["type"]
      when "integer"  then content.to_i
      when "boolean"  then content == "true"
      when "datetime" then Time.parse(content)
      when "date"     then Date.parse(content)
      else                 content
      end
    else
      value.empty? ? nil : value.inject({}) do |h,(k,v)|
        h[k] = typecast_xml_value(v)
        h
      end
    end
  when Array
    value.map! { |i| typecast_xml_value(i) }
    case value.length
    when 0 then nil
    when 1 then value.first
    else value
    end
  when String
    value
  else
    raise "can't typecast #{value.inspect}"
  end
end