Module: Fog::Oracle::JsonUtils

Included in:
Compute::Oracle::Mock, Core
Defined in:
lib/fog/oracle/core.rb

Instance Method Summary collapse

Instance Method Details

#json_decode(body) ⇒ Object



24
25
26
27
28
29
# File 'lib/fog/oracle/core.rb', line 24

def json_decode(body)
  parsed = Fog::JSON.decode(body)
  snakecase_hash_keys(parsed)
  # decode_time_attrs(parsed)
  parsed
end

#json_encode(body) ⇒ Object



19
20
21
22
# File 'lib/fog/oracle/core.rb', line 19

def json_encode(body)
  encoded = Fog::JSON.encode(body)
  encoded
end

#snakecase_hash_keys(value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/oracle/core.rb', line 31

def snakecase_hash_keys(value)
  case value
  when Hash
    value.keys.each do |key|
      new_key = key.underscore
      value[new_key] = value.delete(key)
      snakecase_hash_keys(value[new_key])
    end
  when Array
    value.each do |it|
      snakecase_hash_keys(it)
    end
  end
end