Sha256: 2a52588c7409c1da226abf338afa87868728fc20a677b30a54edabe463dd9248

Contents?: true

Size: 1.45 KB

Versions: 157

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'cgi'

module Aws
  # @api private
  module Util
    class << self

      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

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

      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

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

      def monotonic_seconds
        monotonic_milliseconds / 1000.0
      end

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

    end
  end
end

Version data entries

157 entries across 157 versions & 1 rubygems

Version Path
aws-sdk-core-3.191.6 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.5 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.4 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.3 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.2 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.1 lib/aws-sdk-core/util.rb
aws-sdk-core-3.191.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.190.3 lib/aws-sdk-core/util.rb
aws-sdk-core-3.190.2 lib/aws-sdk-core/util.rb
aws-sdk-core-3.190.1 lib/aws-sdk-core/util.rb
aws-sdk-core-3.190.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.189.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.188.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.187.1 lib/aws-sdk-core/util.rb
aws-sdk-core-3.187.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.186.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.185.2 lib/aws-sdk-core/util.rb
aws-sdk-core-3.185.1 lib/aws-sdk-core/util.rb
aws-sdk-core-3.185.0 lib/aws-sdk-core/util.rb
aws-sdk-core-3.184.0 lib/aws-sdk-core/util.rb