machinio/solrb

View on GitHub
lib/solr/support/hash_extensions.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Solr
  module Support
    module HashExtensions
      extend self

      def symbolize_recursive(hash)
        {}.tap do |h|
          hash.each { |key, value| h[key.to_sym] = transform(value) }
        end
      end

      private

      def transform(thing)
        case thing
        when Hash then symbolize_recursive(thing)
        when Array then thing.map { |v| transform(v) }
        else; thing
        end
      end

      refine Hash do
        def deep_symbolize_keys
          HashExtensions.symbolize_recursive(self)
        end
      end
    end
  end
end