Sha256: 7188d6487bb8c414b8f4a0bb6a0836843a946323aa5ec8330159c8862dc87f17

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

class Hash
  # Example usage:
  #   @hash.dig(:k1)          # same as @hash[:k1]
  #   @hash.dig(:k1, :k2)     # same as @hash[:k1] && @hash[:k1][:k2]
  #   @hash.dig(:k1, :k2, k3) # same as @hash[:k1] && @hash[:k1][:k2] && @hash[:k1][:k2][:k3]
  def dig(*path)
    path.inject(self) do |location, key|
      location.respond_to?(:keys) ? location[key] : nil
    end
  end
  
  # Destructively convert all keys to strings.
  def recursive_stringify_keys!
    keys.each do |key|
      value = delete(key)

      self[key.to_s] =
        case (value)
        when Hash
          value.recursive_stringify_keys!
        else
          value
        end
    end

    self
  end
end

class Net::HTTP
  # Getting rid of the 'warning: peer certificate won't be verified in this SSL session'
  alias_method :old_initialize, :initialize
  def initialize(*args)
    old_initialize(*args)

    @ssl_context = OpenSSL::SSL::SSLContext.new
    @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postageapp-1.2.0 lib/postageapp/utils.rb