Sha256: 9ae99849e1994aea7019dcd77c7d7a19dea3c5c14295ea9903a145e7f9665cdc

Contents?: true

Size: 699 Bytes

Versions: 13

Compression:

Stored size: 699 Bytes

Contents

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

13 entries across 13 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/extensions/deep_symbolize_hash.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.5 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.4 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.3 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.2 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.2.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.1.0 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.0.3 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.0.2 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.0.1 lib/grape/extensions/deep_symbolize_hash.rb
grape-1.0.0 lib/grape/extensions/deep_symbolize_hash.rb