Sha256: 74c16ec1ec5dcac49ec8216e7c492f48f92601792c62e35ad95636544edd9740

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  module Agent
    module HashExtensions
      module_function

      # recurses through hashes and arrays and stringifies keys
      def stringify_keys_in_object(object)
        case object
        when Hash
          object.inject({}) do |memo, (k, v)|
            memo[k.to_s] = stringify_keys_in_object(v)
            memo
          end
        when Array
          object.map {|o| stringify_keys_in_object(o)}
        else
          object
        end
      end

       # recurses through hashes and arrays and symbolizes keys
      def symbolize_keys_in_object(object)
        case object
        when Hash
          object.inject({}) do |memo, (k, v)|
            memo[k.to_sym] = symbolize_keys_in_object(v)
            memo
          end
        when Array
          object.map {|o| symbolize_keys_in_object(o)}
        else
          object
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
newrelic_rpm-3.18.1.330 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.18.0.329 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.17.2.327 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.17.1.326 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.17.0.325 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.16.3.323 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.16.2.321 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.16.1.320 lib/new_relic/agent/hash_extensions.rb
newrelic_rpm-3.16.0.318 lib/new_relic/agent/hash_extensions.rb