Sha256: 1431185274e2eb3d27f4b333fc7a3b087a3bd51155d7324cf25c7b80eefb3feb

Contents?: true

Size: 730 Bytes

Versions: 15

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Extensions
    module DeepSymbolizeHash
      def self.deep_symbolize_keys_in(object)
        case object
        when ::Hash
          object.each_with_object({}) do |(key, value), new_hash|
            new_hash[symbolize_key(key)] = deep_symbolize_keys_in(value)
          end
        when ::Array
          object.map { |element| deep_symbolize_keys_in(element) }
        else
          object
        end
      end

      def self.symbolize_key(key)
        if key.is_a?(Symbol)
          key
        elsif key.is_a?(String)
          key.to_sym
        elsif key.respond_to?(:to_sym)
          key.to_sym
        else
          key
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
grape-1.7.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.7.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.6.2 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.6.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.6.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.5.3 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.5.2 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.5.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.5.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/extensions/deep_symbolize_hash.rb
grape-1.4.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.3.3 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.3.2 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.3.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.3.0 lib/grape/extensions/deep_symbolize_hash.rb