Module: Aws::Util Private

Defined in:
lib/aws-sdk-core/util.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.copy_hash(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
# File 'lib/aws-sdk-core/util.rb', line 19

def copy_hash(hash)
  if Hash === hash
    deep_copy(hash)
  else
    raise ArgumentError, "expected hash, got `#{hash.class}`"
  end
end

.deep_copy(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aws-sdk-core/util.rb', line 27

def deep_copy(obj)
  case obj
  when nil then nil
  when true then true
  when false then false
  when Hash
    obj.inject({}) do |h, (k,v)|
      h[k] = deep_copy(v)
      h
    end
  when Array
    obj.map { |v| deep_copy(v) }
  else
    if obj.respond_to?(:dup)
      obj.dup
    elsif obj.respond_to?(:clone)
      obj.clone
    else
      obj
    end
  end
end

.deep_merge(left, right) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
# File 'lib/aws-sdk-core/util.rb', line 11

def deep_merge(left, right)
  case left
  when Hash then left.merge(right) { |key, v1, v2| deep_merge(v1, v2) }
  when Array then right + left
  else right
  end
end

.deserialize_number(str) ⇒ Number

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The input as a number.

Parameters:

  • str (String)

Returns:

  • (Number)

    The input as a number



84
85
86
87
88
89
90
91
92
# File 'lib/aws-sdk-core/util.rb', line 84

def deserialize_number(str)
  case str
  when 'Infinity' then ::Float::INFINITY
  when '-Infinity' then -::Float::INFINITY
  when 'NaN' then ::Float::NAN
  when nil then nil
  else str.to_f
  end
end

.deserialize_time(value) ⇒ Time

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (String)

Returns:

  • (Time)


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/aws-sdk-core/util.rb', line 96

def deserialize_time(value)
  case value
  when nil then nil
  when /^[\d.]+$/ then Time.at(value.to_f).utc
  else
    begin
      fractional_time = Time.parse(value).to_f
      Time.at(fractional_time).utc
    rescue ArgumentError
      raise "unhandled timestamp format `#{value}'"
    end
  end
end

.monotonic_millisecondsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
# File 'lib/aws-sdk-core/util.rb', line 50

def monotonic_milliseconds
  if defined?(Process::CLOCK_MONOTONIC)
    Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
  else
    DateTime.now.strftime('%Q').to_i
  end
end

.monotonic_secondsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/aws-sdk-core/util.rb', line 58

def monotonic_seconds
  monotonic_milliseconds / 1000.0
end

.serialize_number(input) ⇒ Number, String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The serialized number.

Parameters:

  • input (Number)

Returns:

  • (Number, String)

    The serialized number



73
74
75
76
77
78
79
80
# File 'lib/aws-sdk-core/util.rb', line 73

def serialize_number(input)
  if input == ::Float::INFINITY then 'Infinity'
  elsif input == -::Float::INFINITY then '-Infinity'
  elsif input&.nan? then 'NaN'
  else
    input
  end
end

.str_2_bool(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



62
63
64
65
66
67
68
69
# File 'lib/aws-sdk-core/util.rb', line 62

def str_2_bool(str)
  case str.to_s
  when "true" then true
  when "false" then false
  else
    nil
  end
end