Sha256: c54f7870b37198ce4ce99f5f4895536cd6f327557baeef8893da32a5482d9b11

Contents?: true

Size: 625 Bytes

Versions: 16

Compression:

Stored size: 625 Bytes

Contents

# encoding: utf-8

module Hyperdrive
  module Utils
    def self.sanitize_keys(keys_to_keep, hash)
      Hash[hash.select do |key, value|
        keys_to_keep.include? key
      end]
    end

    def self.symbolize_keys(hash)
      hash.inject({}) do |result, (key, value)|
       result.merge!(Hash[
          case key
          when String then key.to_sym
          else key
          end,
          case value
          when Hash then symbolize_keys(value)
          when Array then value.map! { |v| v.is_a?(Hash) ? symbolize_keys(v) : v } ; value
          else value
          end
        ])
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hyperdrive-0.0.21 lib/hyperdrive/utils.rb
hyperdrive-0.0.20 lib/hyperdrive/utils.rb
hyperdrive-0.0.19 lib/hyperdrive/utils.rb
hyperdrive-0.0.18 lib/hyperdrive/utils.rb
hyperdrive-0.0.17 lib/hyperdrive/utils.rb
hyperdrive-0.0.16 lib/hyperdrive/utils.rb
hyperdrive-0.0.15 lib/hyperdrive/utils.rb
hyperdrive-0.0.14 lib/hyperdrive/utils.rb
hyperdrive-0.0.13 lib/hyperdrive/utils.rb
hyperdrive-0.0.12 lib/hyperdrive/utils.rb
hyperdrive-0.0.11 lib/hyperdrive/utils.rb
hyperdrive-0.0.10 lib/hyperdrive/utils.rb
hyperdrive-0.0.9 lib/hyperdrive/utils.rb
hyperdrive-0.0.8 lib/hyperdrive/utils.rb
hyperdrive-0.0.7 lib/hyperdrive/utils.rb
hyperdrive-0.0.6 lib/hyperdrive/utils.rb